Last active
October 3, 2018 13:01
-
-
Save kovalbogdan95/25b2107d3a19df63f2ccd681405e051c to your computer and use it in GitHub Desktop.
PostgreSQL Administration
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
| # Login to database | |
| sudo -u postgres psql | |
| # Creating user | |
| sudo -u postgres createuser <username> | |
| # Creating Database | |
| sudo -u postgres createdb <dbname> | |
| # Giving the user a password | |
| sudo -u postgres psql | |
| psql=# alter user <username> with encrypted password '<password>'; | |
| # Granting privileges on database | |
| psql=# grant all privileges on database <dbname> to <username> ; | |
| # Same in psql | |
| CREATE DATABASE yourdbname; | |
| CREATE USER youruser WITH ENCRYPTED PASSWORD 'yourpass'; | |
| GRANT ALL PRIVILEGES ON DATABASE yourdbname TO youruser; | |
| # Create database backup | |
| pg_dump -U <user> -h localhost <db name> > dump.sql | |
| # promt password here | |
| # Restoring database | |
| psql -U <user> -d <dbname> -h localhost < dump.sql | |
| # or | |
| pg_restore -U <username> -d <dbname> -1 dump.sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment