summaryrefslogtreecommitdiffstats
path: root/software/postgres.page
blob: 32f2fe4bf4e14206044ea795306d2ab4d7ab4a28 (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
36
37

Start a quick local docker database:

    docker run -p 5432:5432 postgres:latest

Connect (from outside):

    psql -h localhost -w postgres

Dump current schema with something like:

    docker exec 6a018d9d8ef0 pg_dump -U postgres postgres -s | rg -v ^- > schema.sql

Basic status from the psql command line:

    \l+     (list databases)
    \dt+    (describe table)

## Temporary Databases in Tests

Try `pg_tmp`, though it may not work with high concurrency (due to internal
postgres locking), and might need special configuration in CI environments.

Debian also ships with `pg_virtualenv` for temporary databases.

---------

More refs/links:

- https://stackoverflow.com/questions/9604723/alternate-output-format-for-psql
- https://brandur.org/postgres-connections
- https://www.citusdata.com/blog/2017/07/16/customizing-my-postgres-shell-using-psqlrc/
- `bind "^R" em-inc-search-prev`
- https://www.citusdata.com/blog/2019/07/17/postgres-tips-for-average-and-power-user/
- https://github.com/citusdata/pg_auto_failover
- https://repmgr.org/