Last active
August 29, 2018 13:40
-
-
Save alexandervantrijffel/b51eb57a18c1edaef6e619f355dc520d to your computer and use it in GitHub Desktop.
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
# install | |
sudo apt-get update | |
sudo apt-get install -y postgresql-10 | |
#add user | |
sudo -i -u postgres | |
CREATE USER mydbuser WITH PASSWORD 'mypassword'; | |
GRANT SELECT, INSERT, UPDATE, DELETE | |
ON ALL TABLES IN SCHEMA public | |
TO mydbuser; | |
createuser --interactive # (in postgres user shell) | |
createdb mynewdb | |
dropdb mynewdb | |
psql | |
#select database | |
psql -d mynewdb | |
\q | |
# list databases | |
psql -U pgadmin -l | |
# OR | |
\l | |
# list all tables | |
\dt *.* | |
# connect to db1 | |
\c db1cd | |
# ALLOW access from docker images | |
ufw allow from 172.17.0.0/24 proto tcp to any port 5432 | |
ufw allow from 127.0.0.0/24 proto tcp to any port 5432 | |
# in /etc/postgresql/9.5/main/postgresql.conf, set listen_address to: | |
listen_addresses = '*' | |
# in /etc/postgresql/9.5/main/pg_hba.conf, add: | |
host all all 0.0.0.0/0 md5 | |
host all all ::/0 md5 | |
service postgresql restart | |
# copy table with indexes | |
create table listingbackup2 ( like listing INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING INDEXES ); | |
# backup database | |
pg_dump dbname > filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment