synth.download/notes/postgres.md

793 B

Postgresql

Creating a user and the database

To create a new user within postgresql, enter the shell via helperbot --psql.

First we'll create the user. Use the following:

CREATE USER <user> WITH ENCRYPTED PASSWORD '<password>';

Now within the shell, you can just. Type in \q to quit.

CREATE DATABASE <db name>;

Now you need to give the user proper permissions to access the database, otherwise it will fail to work with whatever application we want to hook it up with.

GRANT ALL PRIVILEGES ON DATABASE <db name> TO <user>;
\c <db name> -- switch to the database
GRANT ALL ON SCHEMA public TO <user>;

Deleting a user and their database

If you ever need to delete a user and their database:

DROP DATABASE <db name>;
DROP USER <user>;