blog/content/docs/postgresql.md

62 lines
1.5 KiB
Markdown
Raw Normal View History

2022-08-22 18:43:36 +02:00
---
2022-08-22 18:55:16 +02:00
title: "PostgreSQL"
2022-08-22 18:43:36 +02:00
weight: 1
# bookFlatSection: false
# bookToc: true
# bookHidden: false
# bookCollapseSection: false
# bookComments: false
# bookSearchExclude: false
---
2022-08-22 18:55:16 +02:00
# PostgreSQL
*On this page, `$` means the command must be run as a user with adequate rights such as the `postgres` user.*
## Installation
### Archlinux
On archlinux, PostgreSQL can be installed using the `postgresql` package from `[extra]`.
Major PostgreSQL upgrades are breaking. Instructions from the [official documentation](https://www.postgresql.org/docs/current/upgrading.html) should be followed.
Upgrades can be prevented by adding `postgresql` and `postgresql-libs` to `IgnorePkg` in `/etc/pacman.conf`.
2022-08-22 18:43:36 +02:00
## Filesystem preparation
In case a Btrfs filesystem is used, Copy-on-Write should be disabled first.
## Initial setup
The database can be initialized using the following command. Locale defaults to current environment locale.
```
$ initdb --locale C.UTF-8 --encoding=UTF8 -D /var/lib/postgres/data --data-checksums
```
2022-08-22 18:55:16 +02:00
PostgreSQL can then be started using the `postgresql` systemd service.
2022-08-22 18:43:36 +02:00
## Usage
### Creating users
The following command can be used:
```
$ createuser [--interactive]
```
Additionnal options can be used to give permissions to the user (usually not needed).
Users can be deleted using the following command:
```
$ dropuser [-i/--interactive] [user]
```
### Creating databases
The following command can be used:
```
$ createdb [-O owner] [dbname [description]]
```
## Sources
1. <https://wiki.archlinux.org/title/PostgreSQL>