synth.download/notes/postgres.md

30 lines
793 B
Markdown
Raw Normal View History

2025-08-05 00:42:35 -05:00
# Postgresql
2025-07-19 23:52:19 -05:00
2025-08-05 00:42:35 -05:00
## Creating a user and the database
2025-07-19 23:52:19 -05:00
To create a new user within postgresql, enter the shell via `helperbot --psql`.
First we'll create the user. Use the following:
```sql
CREATE USER <user> WITH ENCRYPTED PASSWORD '<password>';
```
Now within the shell, you can just. Type in `\q` to quit.
```sql
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.
```sql
GRANT ALL PRIVILEGES ON DATABASE <db name> TO <user>;
\c <db name> -- switch to the database
GRANT ALL ON SCHEMA public TO <user>;
```
2025-08-05 00:42:35 -05:00
## Deleting a user and their database
2025-07-19 23:52:19 -05:00
If you ever need to delete a user and their database:
```sql
DROP DATABASE <db name>;
DROP USER <user>;
```