2021/01/04

PostgreSQL ver.12からver.13へのアップグレード

何回かやっているはずだが、覚えていないのでPostgreSQLのアップグレードのメモ。

eselect postgresql listでインストールされているPostgreSQLのバージョンの一覧が表示されるし、デフォルトのバージョンをeselect postgresql setで指定できる。

まず、postgresql-12は停止する

続いて、/etc/conf.d/postgresql-12と、/etc/conf.d/postgresql-13の整合性を取る。

以下はrootではエラーになるので、su postgresしておく。

postgres@edo /data/lib/postgresql Mon Jan  4 21:45:37 2021 JST(+0900)
$ mkdir data13

postgres@edo /data/lib/postgresql Mon Jan  4 21:45:40 2021 JST(+0900)
$ chmod og= data13

postgres@edo /data/lib/postgresql Mon Jan  4 21:45:41 2021 JST(+0900)
$ initdb13 -E UTF8 --locale=en_US.UTF-8 --lc-collate=C /data/lib/postgresql/data13/
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locales
  COLLATE:  C
  CTYPE:    en_US.UTF-8
  MESSAGES: en_US.UTF-8
  MONETARY: en_US.UTF-8
  NUMERIC:  en_US.UTF-8
  TIME:     en_US.UTF-8
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /data/lib/postgresql/data13 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... JST-09
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb13: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /data/lib/postgresql/data13/ -l logfile start


postgres@edo /data/lib/postgresql Mon Jan  4 21:46:00 2021 JST(+0900)
$ pg_upgrade13 -d /data/lib/postgresql/data12 -D /data/lib/postgresql/data13 -b /usr/lib64/postgresql-12/bin/ -B /usr/lib64/postgresql-13/bin/
Performing Consistency Checks
-----------------------------
Checking cluster versions                                   ok
Checking database user is the install user                  ok
Checking database connection settings                       ok
Checking for prepared transactions                          ok
Checking for reg* data types in user tables                 ok
Checking for contrib/isn with bigint-passing mismatch       ok
Creating dump of global objects                             ok
Creating dump of database schemas
                                                            ok
Checking for presence of required libraries                 ok
Checking database user is the install user                  ok
Checking for prepared transactions                          ok
Checking for new cluster tablespace directories             ok

If pg_upgrade fails after this point, you must re-initdb the
new cluster before continuing.

Performing Upgrade
------------------
Analyzing all rows in the new cluster                       ok
Freezing all rows in the new cluster                        ok
Deleting files from new pg_xact                             ok
Copying old pg_xact to new server                           ok
Setting next transaction ID and epoch for new cluster       ok
Deleting files from new pg_multixact/offsets                ok
Copying old pg_multixact/offsets to new server              ok
Deleting files from new pg_multixact/members                ok
Copying old pg_multixact/members to new server              ok
Setting next multixact ID and offset for new cluster        ok
Resetting WAL archives                                      ok
Setting frozenxid and minmxid counters in new cluster       ok
Restoring global objects in the new cluster                 ok
Restoring database schemas in the new cluster
                                                            ok
Copying user relation files
                                                            ok
Setting next OID for new cluster                            ok
Sync data directory to disk                                 ok
Creating script to analyze new cluster                      ok
Creating script to delete old cluster                       ok

Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade so,
once you start the new server, consider running:
    ./analyze_new_cluster.sh

Running this script will delete the old cluster's data files:
    ./delete_old_cluster.sh

postgres@edo /data/lib/postgresql Mon Jan  4 21:46:19 2021 JST(+0900)
$ exit
exit


rootに戻って、PostgreSQLを起動した上で、analyze_new_cluster.shを実行。

root@edo /data/lib/postgresql Mon Jan  4 21:47:33 2021 JST(+0900)
# /etc/init.d/postgresql-13 start
 * /run/postgresql: correcting mode
 * Starting PostgreSQL 13 ...                                                                                                                                         [ ok ]

root@edo /data/lib/postgresql Mon Jan  4 21:47:39 2021 JST(+0900)
# ./analyze_new_cluster.sh
This script will generate minimal optimizer statistics rapidly
so your system is usable, and then gather statistics twice more
with increasing accuracy.  When it is done, your system will
have the default level of optimizer statistics.

If you have used ALTER TABLE to modify the statistics target for
any tables, you might want to remove them and restore them after
running this script because they will delay fast statistics generation.

If you would like default statistics as quickly as possible, cancel
this script and run:
    "/usr/lib64/postgresql-13/bin/vacuumdb" --all --analyze-only

vacuumdb: error: could not connect to database template1: FATAL:  role "root" does not exist

Done

root@edo /data/lib/postgresql Mon Jan  4 21:48:03 2021 JST(+0900)
#

で終わり。

initdbするときのEncodingやLocaleの設定が、PostgreSQL 12の設定と違うと、下記のようなエラーが出るので、適宜調整する

postgres@edo ~ Mon Jan  4 21:37:05 2021 JST(+0900)
$ pg_upgrade13 -d /data/lib/postgresql/data12 -D /data/lib/postgresql/data13 -b /usr/lib64/postgresql-12/bin/ -B /usr/lib64/postgresql-13/bin/
Performing Consistency Checks
-----------------------------
Checking cluster versions                                   ok
Checking database user is the install user                  ok
Checking database connection settings                       ok
Checking for prepared transactions                          ok
Checking for reg* data types in user tables                 ok
Checking for contrib/isn with bigint-passing mismatch       ok
Creating dump of global objects                             ok
Creating dump of database schemas
                                                            ok

encodings for database "postgres" do not match:  old "UTF8", new "SQL_ASCII"
Failure, exiting

postgres@edo ~ Mon Jan  4 21:37:44 2021 JST(+0900)
$ 
$ pg_upgrade13 -d /data/lib/postgresql/data12 -D /data/lib/postgresql/data13 -b /usr/lib64/postgresql-12/bin/ -B /usr/lib64/postgresql-13/bin/
Performing Consistency Checks
-----------------------------
Checking cluster versions                                   ok
Checking database user is the install user                  ok
Checking database connection settings                       ok
Checking for prepared transactions                          ok
Checking for reg* data types in user tables                 ok
Checking for contrib/isn with bigint-passing mismatch       ok
Creating dump of global objects                             ok
Creating dump of database schemas
                                                            ok

lc_ctype values for database "postgres" do not match:  old "en_US.UTF-8", new "C"
Failure, exiting

postgres@edo /data/lib/postgresql Mon Jan  4 21:44:19 2021 JST(+0900)
$



0 件のコメント:

コメントを投稿