notebook/IT/SQL/PostgreSQL/Upgrade.md

59 lines
1.0 KiB
Markdown
Raw Normal View History

2020-12-16 16:40:43 +00:00
# Upgrading PostgreSQL Database
when major release of postgresql is done you need to do some manual action
if not done you can meet issue during request
## action
2021-04-20 21:13:14 +00:00
need to have **postgresqk-old-upgrade** installed on arch
2020-12-16 16:40:43 +00:00
- stop service
2021-04-20 21:13:14 +00:00
2020-12-16 16:40:43 +00:00
```systemctl stop postgresql.service```
2021-04-20 21:13:14 +00:00
2020-12-16 16:40:43 +00:00
- rename cluster directory
2021-04-20 21:13:14 +00:00
```bash
mv /var/lib/postgres/data /var/lib/postgres/olddata
2020-12-16 16:40:43 +00:00
mkdir /var/lib/postgres/data /var/lib/postgres/tmp
chown postgres:postgres /var/lib/postgres/data /var/lib/postgres/tmp
```
2021-04-20 21:13:14 +00:00
2020-12-16 16:40:43 +00:00
- log in postgres account
2021-04-20 21:13:14 +00:00
```bash
2020-12-16 16:40:43 +00:00
sudo -iu postgres
cd /var/lib/postgres/tmp
```
2021-04-20 21:13:14 +00:00
2020-12-16 16:40:43 +00:00
- launch upgrade
2021-04-20 21:13:14 +00:00
```bash
2020-12-16 16:40:43 +00:00
pg_upgrade -b /opt/pgsql-PG_VERSION/bin -B /usr/bin -d /var/lib/postgres/olddata -D /var/lib/postgres/data
```
2021-04-20 21:13:14 +00:00
2020-12-16 16:40:43 +00:00
- check both pg_hba.conf in new and old cluster
- restart server `sc-start postgresql`
2021-04-19 08:45:07 +00:00
2021-04-20 21:13:14 +00:00
## sequece manipulation
2021-04-19 08:45:07 +00:00
sequence are use to generate uniq identifier
2021-04-20 21:13:14 +00:00
2021-04-19 08:45:07 +00:00
- get sequence value
2021-04-20 21:13:14 +00:00
2021-04-19 08:45:07 +00:00
```SQL
select * from name_seq;
```
2021-04-20 21:13:14 +00:00
2021-04-19 08:45:07 +00:00
- increment sequence value
2021-04-20 21:13:14 +00:00
2021-04-19 08:45:07 +00:00
```SQL
select nextval(name_seq);
```
- set sequence value:
2021-04-20 21:13:14 +00:00
2021-04-19 08:45:07 +00:00
```SQL
select setval(name_seq,newvalue);
2021-04-20 21:13:14 +00:00
```