LoFa
Add
Login
Search
Title:
Tag1 for Path:
a single word in lower characters
Tag2 for Path:
List of alternative single tags:
one or many words in lower characters, separated by comma or space
Text:
<p>This is a straight forward guide for safely upgrade PostgreSQL 11</p> <b>First take a snapshot or save the entire virtual machine.</b> <h2>First get some information about the environment on the virtual machine.</h2> <code>pkg info | grep sql</code> <samp> php70-pdo_pgsql-7.0.14 The pdo_pgsql shared extension for php php70-pgsql-7.0.14 The pgsql shared extension for php postgresql95-client-9.5.5_1 PostgreSQL database (client) postgresql95-server-9.5.5_1 PostgreSQL is the most advanced open-source database available anywhere </samp> <p>Show Versions of the PostgreSQL databases</p> <code>/usr/local/bin/psql -U pgsql -d dbwnk2016 -t --command "show server_version"</code> <samp> 9.5.5 </samp> <p>List all databases</p> <code>psql -U pgsql -d dbwnk2016 -l</code> <samp> List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -------------+-------+----------+---------+-------+------------------- postgres | pgsql | UTF8 | C | C | template0 | pgsql | UTF8 | C | C | =c/pgsql + template1 | pgsql | UTF8 | C | C | =c/pgsql + dbwnk2016 | pgsql | UTF8 | C | C | (4 rows) </samp> <p>In our case we only need to upgrade database "dbwnk2016".</p> <h2>Take a dump of the whole PostgreSQL databases</h2> <code>/usr/local/bin/pg_dump --create --encoding=UTF8 --column-inserts --dbname=dbwnk2016 \</code> <code> --format=p --inserts --username=pgsql \</code> <code> --file=/usr/local/www/wnk20170106.sql</code> <p>Check size of the exported data and ddl</p> <code>ls -altr /usr/local/www/*.sql</code> <samp> -rw-r--r-- 1 root wheel 1370834115 Jan 6 12:56 /usr/local/www/wnk20170106.sql </samp> <h2>Update PostgreSQL default version in FreeBSD config files</h2> <p>At the time of writing the default version for postgreSQL was version 9.3. However, we need version 9.6.</p> <code>vi /usr/ports/Mk/bsd.default-versions.mk</code> <p>Change the following values</p> <samp> # Possible values: 9.2, 9.3, 9.4, 9.5, 9.6 PGSQL_DEFAULT?= 9.6 </samp> <h2>Stop PostgreSQL 9.5 service and delete binaries</h2> <code>service postgresql stop</code> <code>pkg delete -fy postgresql95-client-9.5.5_1</code> <samp> Updating database digests format: 100% Checking integrity... done (0 conflicting) Deinstallation has been requested for the following 1 packages (of 0 packages in the universe): Installed packages to be REMOVED: postgresql95-client-9.5.5_1 Number of packages to be removed: 1 The operation will free 10 MiB. [1/1] Deinstalling postgresql95-client-9.5.5_1... [1/1] Deleting files for postgresql95-client-9.5.5_1: 100% </samp> <code> pkg delete -fy postgresql95-server-9.5.5_1 </code> <samp> Checking integrity... done (0 conflicting) Deinstallation has been requested for the following 1 packages (of 0 packages in the universe): Installed packages to be REMOVED: postgresql95-server-9.5.5_1 Number of packages to be removed: 1 The operation will free 18 MiB. [1/1] Deinstalling postgresql95-server-9.5.5_1... [1/1] Deleting files for postgresql95-server-9.5.5_1: 100% ==> You should manually remove the "pgsql" user. ==> You should manually remove the "pgsql" group </samp> <p>We save to old environment data</p> <code> mv /usr/local/pgsql /usr/local/pgsql.old; ls -altr /usr/local/pgsql.old </code> <samp> total 28 -rw------- 1 pgsql pgsql 179 Dec 11 11:05 pg_upgrade_server.log -rw------- 1 pgsql pgsql 179 Dec 11 11:05 pg_upgrade_utility.log -rw------- 1 pgsql pgsql 326 Dec 11 11:05 pg_upgrade_internal.log drwxr-xr-x 3 pgsql pgsql 512 Dec 11 11:05 . -rw------- 1 pgsql pgsql 246 Dec 11 11:18 .psql_history drwx------ 19 pgsql pgsql 1024 Dec 11 11:38 data drwxr-xr-x 17 root wheel 512 Dec 11 11:39 .. </samp> <h2>Install PostgreSQL 9.6</h2> <p>The installation of the PostgreSQL server software also installs the PostgreSQL client</p> <code> portsnap fetch update </code> <code> cd /usr/ports/databases/postgresql96-server/ && make install clean </code> <samp> Installing postgresql96-server-9.6.1_1... ===> Creating groups. Creating group 'postgres' with gid '770'. ===> Creating users Creating user 'postgres' with uid '770'. =========== BACKUP YOUR DATA! ============= As always, backup your data before upgrading. If the upgrade leads to a higher minor revision (e.g. 8.3.x -> 8.4), a dump and restore of all databases is required. This is *NOT* done by the port! =========================================== For procedural languages and postgresql functions, please note that you might have to update them when updating the server. If you have many tables and many clients running, consider raising kern.maxfiles using sysctl(8), or reconfigure your kernel appropriately. The port is set up to use autovacuum for new databases, but you might also want to vacuum and perhaps backup your database regularly. There is a periodic script, /usr/local/etc/periodic/daily/502.pgsql, that you may find useful. You can use it to backup and perform vacuum on all databases nightly. Per default, it performs `vacuum analyze'. See the script for instructions. For autovacuum settings, please review ~pgsql/data/postgresql.conf. If you plan to access your PostgreSQL server using ODBC, please consider running the SQL script /usr/local/share/postgresql/odbc.sql to get the functions required for ODBC compliance. Please note that if you use the rc script, /usr/local/etc/rc.d/postgresql, to initialize the database, unicode (UTF-8) will be used to store character data by default. Set postgresql_initdb_flags or use login.conf settings described below to alter this behaviour. See the start rc script for more info. To set limits, environment stuff like locale and collation and other things, you can set up a class in /etc/login.conf before initializing the database. Add something similar to this to /etc/login.conf: --- postgres:\ :lang=en_US.UTF-8:\ :setenv=LC_COLLATE=C:\ :tc=default: --- and run `cap_mkdb /etc/login.conf'. Then add 'postgresql_class="postgres"' to /etc/rc.conf. ====================================================================== To initialize the database, run /usr/local/etc/rc.d/postgresql initdb You can then start PostgreSQL by running: /usr/local/etc/rc.d/postgresql start For postmaster settings, see ~pgsql/data/postgresql.conf NB. FreeBSD's PostgreSQL port logs to syslog by default See ~pgsql/data/postgresql.conf for more info ====================================================================== To run PostgreSQL at startup, add 'postgresql_enable="YES"' to /etc/rc.conf ===> SECURITY REPORT: This port has installed the following files which may act as network servers and may therefore pose a remote security risk to the system. /usr/local/bin/postgres This port has installed the following startup scripts which may cause these network services to be started at boot time. /usr/local/etc/rc.d/postgresql If there are vulnerabilities in these programs there may be a security risk to the system. FreeBSD makes no guarantee about the security of ports included in the Ports Collection. Please type 'make deinstall' to deinstall the port if this is a concern. For more information, and contact details about the security status of this software, see the following webpage: http://www.postgresql.org/ ===> Cleaning for postgresql96-client-9.6.1 ===> Cleaning for postgresql96-server-9.6.1_1 </samp> <h2>Next we create an initial database</h2> <code> /usr/local/etc/rc.d/postgresql initdb </code> <samp> 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 locale "C". The default text search configuration will be set to "english". Data page checksums are disabled. creating directory /var/db/postgres/data96 ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting dynamic shared memory implementation ... posix creating configuration files ... ok running bootstrap script ... ok performing post-bootstrap initialization ... ok syncing data to disk ... ok 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: /usr/local/bin/pg_ctl -D /var/db/postgres/data96 -l logfile start </samp> <p>Let's start the database</p> <code> service postgresql start </code> <samp> LOG: ending log output to stderr HINT: Future log output will go to log destination "syslog". </samp> <h2>Restore the exported databases</h2> <code> su postgres </code> <code> psql -f /usr/local/www/wnk20170106b.sql > /var/log/wnk20170106.log </code> <code> psql -l dbwnk2016 </code> <h2>Reboot Virtual Maching</h2> <code> shutdown -r now </code> <h2>Cleanup</h2> <p>After successful upgrade you should delete the snapshot of the virtual machine and delete the files in /usr/local/pgsql.old.</p>
URL:
Operation:
Delete
Update
Insert
Template Prompt