Created
February 17, 2020 10:58
-
-
Save plcgi1/a498521509583094568bf00de16112fb to your computer and use it in GitHub Desktop.
PG initial setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1.console#> psql postgres | |
| postgres=# ALTER USER librarian WITH SUPERUSER; | |
| 2.postgres=# CREATE USER username WITH ENCRYPTED PASSWORD 'secretpassword'; | |
| 3.postgres=# CREATE database "db-name" | |
| 4.postgres=# GRANT ALL PRIVILEGES ON DATABASE "db-name" TO username; | |
| 5.console#> pg_restore latest.dump > 2018-10-06.sql | |
| 6. psql -U username < 2018-10-06.sql | |
| # script pgdump | |
| PGHOST=dbhost | |
| PGPORT=dbport | |
| PGDATABASE=dbname | |
| PGUSER=dbuser | |
| PGPASSWORD=dbpassword | |
| OUTPUT="$(date +%Y-%m-%d).sql"; | |
| echo $OUTPUT | |
| pg_dump postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/$PGDATABASE > $OUTPUT | |
| perl -i -pe 's/xhoclfrzwegbrt/plcgi1/g' $OUTPUT | |
| psql postgres -h localhost -p 31200 -c 'drop database DBNAME;' | |
| psql postgres -h localhost -p 31200 -c 'create database DBNAME;' | |
| psql aqer -h localhost -p 31200 < $OUTPUT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment