m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/postgres.md
blob: ddca2e572b72748af5d6393c2d4db4e1b9fde998 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# The PostgreSQL DBMS

Default user, db: `postgres`

## `psql` CLI

    psql <database> <user>

### Meta commands

- `\c[onnect]`: connects to a database, new server (can specify dbname, username,
host, port, etc., use `-` to leave unspecfied)
- `\dt`: list tables
  - There's a bunch of complicated `\d*` commands

## User management

Everything should be done as user `postgres`.

New user:

    createuser --pwprompt mypguser

Change password:

    # in `psql`
    ALTER ROLE user WITH PASSWORD 'xxx';

## New database

    sudo su postgres
    createdb -O mypguser mypgdatabase

    # delete db
    dropdb mypgdatabase