feat: add doc/postgres-upgrade-pg_upgrade.md and doc/postgres-upgrade-pg_upgradecluster.md
This commit is contained in:
parent
3ed6d121f3
commit
3ab07df114
|
@ -1,28 +1,17 @@
|
||||||
# Connect to Postgres Database Using Psql
|
# Connect to Postgres Database Using Psql
|
||||||
|
|
||||||
* configure Postgres like [this](./postgres.md)
|
* OPTION: connect to Postgres as admin user
|
||||||
|
|
||||||
* create a database like [this](./postgres-create-db.md)
|
|
||||||
|
|
||||||
* create a use like [this](./postgres-create-user.md)
|
|
||||||
|
|
||||||
* when needed connect to Postgres as admin user locally
|
|
||||||
```
|
```
|
||||||
sudo -u postgres psql postgres -W
|
sudo -u postgres psql -U postgres -W
|
||||||
```
|
```
|
||||||
|
|
||||||
* when needed connect to the database <database name>
|
* OPTION: connect to the database <database name> as user <user name>
|
||||||
as user <user name> locally
|
|
||||||
```
|
```
|
||||||
psql -U <user name> -d <database name> -W
|
psql -U <user name> -d <database name> -W
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
* when needed connect to the database <database name>
|
* OPTION: connect to the database <database name> as user <user name> to a remote Postgres instance at host <host name> and port <port number> (NOTE: Configure Postgres for remote connections like [this](./postgres.md))
|
||||||
as user <user name> to a remote Postgres instance at host
|
|
||||||
<host name> and port <port number>\
|
|
||||||
NOTE: Configure Postgres for remote connections like
|
|
||||||
[this](./postgres.md)
|
|
||||||
```
|
```
|
||||||
psql -h <host name> -p <port number> -U <user name> -d <database name> -W
|
psql -h <host name> -p <port number> -U <user name> -d <database name> -W
|
||||||
```
|
```
|
|
@ -1,9 +1,9 @@
|
||||||
# Create Database with Postgres
|
# Create Database with Postgres
|
||||||
|
|
||||||
* configure Postgres like [this](./postgres.md)
|
* create a new database <database name> and grant privileges to <user name>
|
||||||
|
|
||||||
* create a new database
|
|
||||||
```
|
```
|
||||||
sudo -u postgres psql -W
|
sudo -u postgres psql -W
|
||||||
CREATE DATABASE <database name>;
|
CREATE DATABASE <database name>;
|
||||||
|
GRANT ALL PRIVILEGES ON DATABASE <database name> to <user name>;
|
||||||
|
\q
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
# Create User with Postgres
|
# Create User with Postgres
|
||||||
|
|
||||||
* configure Postgres like [this](./postgres.md)
|
|
||||||
|
|
||||||
* create a database like [this](./postgres-create-db.md)
|
|
||||||
|
|
||||||
* create a database user called <user name> with password <key>
|
* create a database user called <user name> with password <key>
|
||||||
```
|
```
|
||||||
sudo -u postgres psql -W
|
|
||||||
CREATE USER <user name> with encrypted password '<key>';
|
CREATE USER <user name> with encrypted password '<key>';
|
||||||
|
```
|
||||||
|
|
||||||
|
* OPTION: gant user <user_name> access to database <database name>
|
||||||
|
```
|
||||||
GRANT ALL PRIVILEGES ON DATABASE <database name> TO <user name>;
|
GRANT ALL PRIVILEGES ON DATABASE <database name> TO <user name>;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -24,7 +23,7 @@ ALTER USER <user name> WITH ENCRYPTED PASSWORD '<key>';
|
||||||
* OPTION: gant user <user_name> access to database ```postgres``` so that this user is able to login without providing a database
|
* OPTION: gant user <user_name> access to database ```postgres``` so that this user is able to login without providing a database
|
||||||
```
|
```
|
||||||
sudo -u postgres psql -W
|
sudo -u postgres psql -W
|
||||||
grant all privileges on database postgres to <user name>;
|
GRANT ALL PRIVILEGES ON DATABASE postgres to <user name>;
|
||||||
```
|
```
|
||||||
|
|
||||||
* OPTION: gant user <user_name> permission to create databases
|
* OPTION: gant user <user_name> permission to create databases
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
# Upgrade using pg_upgrade
|
||||||
|
|
||||||
|
* check clusters
|
||||||
|
```
|
||||||
|
pg_lsclusters
|
||||||
|
```
|
||||||
|
|
||||||
|
* do
|
||||||
|
```
|
||||||
|
sudo apt update
|
||||||
|
sudo apt upgrade postgresql-xy
|
||||||
|
```
|
||||||
|
|
||||||
|
* install relevant packages
|
||||||
|
```
|
||||||
|
sudo apt-get install postgresql-server-dev-13
|
||||||
|
```
|
||||||
|
|
||||||
|
* make a backup
|
||||||
|
```
|
||||||
|
cd
|
||||||
|
time sudo -u postgres pg_dumpall > bckp-all-2023-08-07
|
||||||
|
```
|
||||||
|
|
||||||
|
* check installed extensions on old version
|
||||||
|
```
|
||||||
|
sudo -u postgres psql -p 5432 postgres
|
||||||
|
\dx
|
||||||
|
```
|
||||||
|
|
||||||
|
* install extension on new version
|
||||||
|
```
|
||||||
|
sudo apt install postgresql-13-postgis-3 --no-install-recommends
|
||||||
|
sudo -u postgres psql -p 5433 postgres
|
||||||
|
\dx
|
||||||
|
CREATE EXTENSION postgis;
|
||||||
|
CREATE EXTENSION hstore;
|
||||||
|
```
|
||||||
|
|
||||||
|
* stop all clusters
|
||||||
|
```
|
||||||
|
sudo systemctl stop postgresql
|
||||||
|
systemctl status postgresql
|
||||||
|
pg_lsclusters
|
||||||
|
```
|
||||||
|
|
||||||
|
* migrate
|
||||||
|
```
|
||||||
|
sudo -iu postgres /usr/lib/postgresql/13/bin/pg_upgrade \
|
||||||
|
-o "-c config_file=/etc/postgresql/11/main/postgresql.conf" \
|
||||||
|
--old-datadir=/var/lib/postgresql/11/main/ \
|
||||||
|
-O "-c config_file=/etc/postgresql/13/main/postgresql.conf" \
|
||||||
|
--new-datadir=/var/lib/postgresql/13/main/ \
|
||||||
|
--old-bindir=/usr/lib/postgresql/11/bin \
|
||||||
|
--new-bindir=/usr/lib/postgresql/13/bin --check --jobs=4
|
||||||
|
```
|
||||||
|
|
||||||
|
* TODO tbc
|
||||||
|
|
||||||
|
* uninstall the previous version
|
||||||
|
```
|
||||||
|
sudo apt purge postgresql-11* postgresql-client- 11*
|
||||||
|
sudo apt autoremove
|
||||||
|
apt list --installed | grep postgresql-11 postgresql-client-11*
|
||||||
|
```
|
|
@ -0,0 +1,81 @@
|
||||||
|
# Upgrade using pg_upgradecluster
|
||||||
|
|
||||||
|
* check clusters
|
||||||
|
```
|
||||||
|
pg_lsclusters
|
||||||
|
```
|
||||||
|
|
||||||
|
* do
|
||||||
|
```
|
||||||
|
sudo apt update
|
||||||
|
sudo apt upgrade postgresql-xy
|
||||||
|
```
|
||||||
|
|
||||||
|
* install relevant packages
|
||||||
|
```
|
||||||
|
sudo apt-get install postgresql-server-dev-13
|
||||||
|
```
|
||||||
|
|
||||||
|
* make a backup
|
||||||
|
```
|
||||||
|
cd
|
||||||
|
time sudo -u postgres pg_dumpall > bckp-all-2023-08-07
|
||||||
|
```
|
||||||
|
|
||||||
|
* check installed extensions on old version
|
||||||
|
```
|
||||||
|
sudo -u postgres psql -p 5432 postgres
|
||||||
|
\dx
|
||||||
|
```
|
||||||
|
|
||||||
|
* OPTION: install extension on new version
|
||||||
|
```
|
||||||
|
sudo apt install postgresql-13-postgis-3 --no-install-recommends
|
||||||
|
sudo -u postgres psql -p 5433 postgres
|
||||||
|
\dx
|
||||||
|
CREATE EXTENSION postgis;
|
||||||
|
CREATE EXTENSION hstore;
|
||||||
|
```
|
||||||
|
|
||||||
|
* stop all clusters
|
||||||
|
```
|
||||||
|
sudo systemctl stop postgresql
|
||||||
|
systemctl status postgresql
|
||||||
|
pg_lsclusters
|
||||||
|
```
|
||||||
|
|
||||||
|
* migrate
|
||||||
|
```
|
||||||
|
sudo systemctl stop postgresql@13-main
|
||||||
|
sudo -u postgres pg_dropcluster 13 main
|
||||||
|
sudo -u postgres pg_upgradecluster 11 main
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
systemctl status postgresql@13-main
|
||||||
|
pg_lsclusters
|
||||||
|
```
|
||||||
|
|
||||||
|
* drop the old cluster:
|
||||||
|
```
|
||||||
|
sudo -u postgres pg_dropcluster 11 main
|
||||||
|
```
|
||||||
|
|
||||||
|
* uninstall the previous version
|
||||||
|
```
|
||||||
|
sudo apt purge postgresql-11* postgresql-client-11*
|
||||||
|
sudo apt autoremove
|
||||||
|
apt list --installed | grep postgresql-11 postgresql-client-11*
|
||||||
|
```
|
||||||
|
|
||||||
|
* do
|
||||||
|
```
|
||||||
|
sudo pg_ctlcluster 13 main stop
|
||||||
|
pg_lsclusters
|
||||||
|
sudo pg_ctlcluster 13 main start
|
||||||
|
pg_lsclusters
|
||||||
|
```
|
||||||
|
|
||||||
|
* vacuum
|
||||||
|
```
|
||||||
|
sudo -u postgres vacuumdb --all --analyze-only
|
||||||
|
sudo -u postgres vacuumdb --all
|
||||||
|
```
|
Loading…
Reference in New Issue