refactor: finish moving ssh-* scripts to own installers
[webi-installers/.git] / postgres / README.md
1 ---
2 title: Postgres
3 homepage: https://www.postgresql.org/
4 tagline: |
5   PostgreSQL: The World's Most Advanced Open Source Relational Database.
6 ---
7
8 To update or switch versions, run `webi postgres@stable` (or `@v10`, `@beta`,
9 etc).
10
11 ## Cheat Sheet
12
13 > Postgres is the all-in-one database for beginners and experts alike. It
14 > handles SQL, 'NoSQL', JSON, HSTORE, Full-Text Search, Messages Queues and
15 > more. Best bang for buck.
16
17 ### Start the postgres server
18
19 Run just once (for development):
20
21 ```bash
22 postgres -D $HOME/.local/share/postgres/var -p 5432
23 ```
24
25 Run as a system service on Linux:
26
27 ```bash
28 sudo env PATH="$PATH" \
29     serviceman add --system --username $(whoami) --name postgres -- \
30     postgres -D "$HOME/.local/share/postgres/var" -p 5432
31 ```
32
33 ### Connect with the psql client
34
35 ```bash
36 psql 'postgres://postgres:postgres@localhost:5432/postgres'
37 ```
38
39 ### Initialize a database with a password
40
41 ```bash
42 echo "postgres" > /tmp/pwfile
43 mkdir -p $HOME/.local/share/postgres/var/
44
45 initdb -D $HOME/.local/share/postgres/var/ \
46     --username postgres --pwfile "/tmp/pwfile" \
47     --auth-local=password --auth-host=password
48
49 rm /tmp/pwfile
50 ```