Skip to content

Instantly share code, notes, and snippets.

@mamachanko
Last active January 10, 2020 09:11
Show Gist options
  • Save mamachanko/1721d30c19dfd38b6746fb8bf66a8beb to your computer and use it in GitHub Desktop.
Save mamachanko/1721d30c19dfd38b6746fb8bf66a8beb to your computer and use it in GitHub Desktop.
TAOP db restore
$ ./taop_init.sh
...
Get:3 http://apt.postgresql.org/pub/repos/apt buster-pgdg InRelease [46.2 kB]
Get:4 http://deb.debian.org/debian buster-updates InRelease [49.3 kB]
Get:5 http://security.debian.org/debian-security buster/updates/main amd64 Packages [168 kB]
Get:6 http://deb.debian.org/debian buster/main amd64 Packages [7,908 kB]
Get:7 http://apt.postgresql.org/pub/repos/apt buster-pgdg/12 amd64 Packages [861 B]
Get:8 http://apt.postgresql.org/pub/repos/apt buster-pgdg/main amd64 Packages [156 kB]
Get:9 http://deb.debian.org/debian buster-updates/main amd64 Packages [5,792 B]
Fetched 8,522 kB in 2s (4,145 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
make-doc
The following NEW packages will be installed:
make postgresql-12-hll postgresql-12-ip4r
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 618 kB of archives.
After this operation, 2,218 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian buster/main amd64 make amd64 4.2.1-1.2 [341 kB]
Get:2 http://apt.postgresql.org/pub/repos/apt buster-pgdg/main amd64 postgresql-12-hll amd64 2.14-1.pgdg100+1 [80.1 kB]
Get:3 http://apt.postgresql.org/pub/repos/apt buster-pgdg/main amd64 postgresql-12-ip4r amd64 2.4.1-2.pgdg100+1 [197 kB]
Fetched 618 kB in 0s (3,041 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package make.
(Reading database ... 13981 files and directories currently installed.)
Preparing to unpack .../make_4.2.1-1.2_amd64.deb ...
Unpacking make (4.2.1-1.2) ...
Selecting previously unselected package postgresql-12-hll.
Preparing to unpack .../postgresql-12-hll_2.14-1.pgdg100+1_amd64.deb ...
Unpacking postgresql-12-hll (2.14-1.pgdg100+1) ...
Selecting previously unselected package postgresql-12-ip4r.
Preparing to unpack .../postgresql-12-ip4r_2.4.1-2.pgdg100+1_amd64.deb ...
Unpacking postgresql-12-ip4r (2.4.1-2.pgdg100+1) ...
Setting up postgresql-12-hll (2.14-1.pgdg100+1) ...
Setting up postgresql-12-ip4r (2.4.1-2.pgdg100+1) ...
Setting up make (4.2.1-1.2) ...
Processing triggers for postgresql-common (210.pgdg100+1) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:
createuser -SDr taop
createdb -O taop taop
psql -d taop -c 'create extension btree_gist'
CREATE EXTENSION
psql -d taop -c 'create extension ip4r'
CREATE EXTENSION
psql -d taop -c 'create extension hll'
CREATE EXTENSION
psql -d taop -c 'create extension cube'
CREATE EXTENSION
psql -d taop -c 'create extension earthdistance'
CREATE EXTENSION
psql -d taop -c 'create extension hstore'
CREATE EXTENSION
psql -d taop -c 'create extension intarray'
CREATE EXTENSION
psql -d taop -c 'create extension pg_trgm'
CREATE EXTENSION
pg_restore -U taop -d taop --use-list=./exclude-extensions.list --no-owner ./taop.dump
pg_restore: while PROCESSING TOC:
pg_restore: from TOC entry 11; 2615 2200 SCHEMA public postgres
pg_restore: error: could not execute query: ERROR: schema "public" already exists
Command was: CREATE SCHEMA public;
pg_restore: from TOC entry 5136; 0 0 COMMENT SCHEMA public postgres
pg_restore: error: could not execute query: ERROR: must be owner of schema public
Command was: COMMENT ON SCHEMA public IS 'standard public schema';
^Cpg_restore: terminated by user
make: *** [Makefile:8: restore] Error 1
$
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
quit() {
echo 👋🏽 goodbyesql
echo stopping db container ...
docker stop db
}
trap quit SIGINT
docker \
run \
--rm \
--detach \
--name db \
--volume $(pwd):/taop \
postgres:12
docker \
exec \
--workdir /taop \
$(docker ps --quiet --filter name=db) \
bash -c '
apt update
apt install -y make postgresql-${PG_MAJOR}-hll postgresql-${PG_MAJOR}-ip4r
PGUSER=postgres make
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment