Skip to content

Instantly share code, notes, and snippets.

@charlespeach
Last active August 29, 2015 14:02
Show Gist options
  • Save charlespeach/d6fd4c9349d092b5ec74 to your computer and use it in GitHub Desktop.
Save charlespeach/d6fd4c9349d092b5ec74 to your computer and use it in GitHub Desktop.
PostgreSQL common commands

Atler owner of db

ALTER DATABASE name OWNER TO new_owner;

Create the user

postgres@hostname:~$ createuser
Enter name of role to add: username
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n
CREATE ROLE
postgres@hostname:~$

Create the DB

postgres@hostname:~$ createdb databasename
CREATE DATABASE
postgres@hostname:~$

Grand access for the user to the DB And last, using the psql command, set a password for the user and grant accesses :

postgres@hostname:~$ psql
postgres=# ALTER USER username WITH ENCRYPTED PASSWORD 'password';
ALTER ROLE
postgres=# GRANT ALL PRIVILEGES ON DATABASE databasename TO username;
GRANT
postgres@hostname:~$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment