LoFa
Add Account
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 Howto explains the upgrade to PostgreSQL 19 on FreeBSD 15.</p> <h2>Check if the Package is available</h2> <code>sudo pkg search --prefix postgresql19-server</code> <pre><samp> postgresql18-server-19.0 Prefix : /usr/local Comment : PostgreSQL is the most advanced open-source database available anywhere </samp></pre> <h2>Save / Backup</h2> <p><b>Take a snapshot of the virtual machine or save the entire server.</b></p> <h2>Get Information about the Environment</h2> <code>pkg info | grep sql</code> <pre><samp> postgresql18-client-18.4 PostgreSQL database (client) postgresql18-server-18.4 PostgreSQL is the most advanced open-source database available anywhere</samp></pre> <h3>Output the Location of the Configuration Directories</h3> <code>pg_config</code> <pre><samp> BINDIR = /usr/local/bin DOCDIR = /usr/local/share/doc/postgresql HTMLDIR = /usr/local/share/doc/postgresql INCLUDEDIR = /usr/local/include PKGINCLUDEDIR = /usr/local/include/postgresql INCLUDEDIR-SERVER = /usr/local/include/postgresql/server LIBDIR = /usr/local/lib PKGLIBDIR = /usr/local/lib/postgresql LOCALEDIR = /usr/local/share/locale MANDIR = /usr/local/share/man SHAREDIR = /usr/local/share/postgresql SYSCONFDIR = /usr/local/etc/postgresql PGXS = /usr/local/lib/postgresql/pgxs/src/makefiles/pgxs.mk 'LDFLAGS_SL=' CC = cc CFLAGS_SL = -fPIC -DPIC LDFLAGS = -L/usr/local/lib -lpthread -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib -Wl,--as-needed -Wl,-R'/usr/local/lib' LDFLAGS_EX = LDFLAGS_SL = LIBS = -lpgcommon -lpgport -lintl -lzstd -lssl -lcrypto -lz -lreadline -lexecinfo -lm VERSION = PostgreSQL 18.4 </samp></pre> <h3>Get a List of the PostgreSQL Databases</h3> <code>/usr/local/bin/psql -U postgres -l</code> <pre><samp> List of databases Name | Owner | Encoding | Locale Provider | Collate | Ctype | Locale | ICU Rules | Access privileges -----------+----------+----------+-----------------+---------+---------+--------+-----------+----------------------- db1 | postgres | UTF8 | libc | C | C.UTF-8 | | | postgres | postgres | UTF8 | libc | C | C.UTF-8 | | | template0 | postgres | UTF8 | libc | C | C.UTF-8 | | | =c/postgres + | | | | | | | | postgres=CTc/postgres (3 rows) </samp></pre> <h3>Dump all PostgreSQL Databases</h3> <code>/usr/local/bin/pg_dump --create --encoding=UTF8 --column-inserts --dbname=db1 --format=p --inserts --username=postgres --file=/usr/local/www/db1_20260808.sql </code> <h3>Check if the Dump Exists</h3> <p>Also check the size of the file!</p> <code>ls -altr /usr/local/www/*.sql </code> <pre><samp></samp></pre> <p>Postgresql Data Dir: /var/db/postgres/data18/</p> <h3>Stop The PostgreSQL Service and Remove Old Packages</h3> <code>sudo service postgresql stop</code><br> <code>sudo pkg delete -fy postgresql18-server-18.4;</code> <pre><samp> Checking integrity... done (0 conflicting) Installed packages to be REMOVED: postgresql18-server: 18.4 Number of packages to be removed: 1 The operation will free 51 MiB. [1/1] Deinstalling postgresql18-server-18.4... [1/1] Deleting files for postgresql18-server-18.4: 100% ==> You should manually remove the "postgres" user ==> You should manually remove the "postgres" group </samp></pre> <code>sudo pkg delete -fy postgresql18-client-18.4</code <pre><samp> Checking integrity... done (0 conflicting) Installed packages to be REMOVED: postgresql18-client: 18.4 Number of packages to be removed: 1 The operation will free 15 MiB. [1/1] Deinstalling postgresql18-client-18.4... [1/1] Deleting files for postgresql18-client-18.4: 100% </samp></pre> <h2>Install PostgreSQL 19 Package</h2> <code>sudo pkg install postgresql19-server</code> <pre><samp> Updating FreeBSD repository catalogue... FreeBSD repository is up to date. All repositories are up to date. New packages to be INSTALLED: postgresql19-client: 19.0 postgresql19-server: 19.0 Number of packages to be installed: 2 The process will require 69 MiB more space. 20 MiB to be downloaded. Proceed with this action? [y/N]: <kbd>y</kbd> [1/2] Fetching postgresql19-server-19.0.pkg: 100% 17 MiB 17.4MB/s 00:01 [2/2] Fetching postgresql19-client-19.0.pkg: 100% 4 MiB 3.7MB/s 00:01 Checking integrity... done (0 conflicting) [1/2] Installing postgresql19-client-19.0... [1/2] Extracting postgresql19-client-19.0: 100% [2/2] Installing postgresql19-server-19.0... ===> Creating groups Using existing group 'postgres' ===> Creating users Using existing user 'postgres' ===> Creating homedir(s) = BACKUP YOUR DATA! = As always, backup your data before upgrading. If the upgrade leads to a higher major revision (e.g. 9.6 -> 10), a dump and restore of all databases is required. This is *NOT* done by the port! See https://www.postgresql.org/docs/current/upgrading.html === [2/2] Extracting postgresql19-server-19.0: 100% ===== Message from postgresql19-server-19.0: -- 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 ~postgres/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_login_class="postgres"' to /etc/rc.conf, or set it as the postgres user's login class in /etc/passwd. ======== To use PostgreSQL, enable it in rc.conf using sysrc postgresql_enable=yes To initialize the database, run service postgresql initdb You can then start PostgreSQL by running: service postgresql start For postmaster settings, see ~postgres/data/postgresql.conf NB. FreeBSD's PostgreSQL port logs to syslog by default See ~postgres/data/postgresql.conf for more info NB. If you're not using a checksumming filesystem like ZFS, you might wish to enable data checksumming. It can be enabled during the initdb phase, by adding the "--data-checksums" flag to the postgresql_initdb_flags rcvar. Otherwise you can enable it later by using pg_checksums. Check the initdb(1) manpage for more info and make sure you understand the performance implications. </samp></pre> <code>sudo service postgresql initdb</code> <pre><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 this locale configuration: locale provider: libc LC_COLLATE: C LC_CTYPE: C.UTF-8 LC_MESSAGES: C.UTF-8 LC_MONETARY: C.UTF-8 LC_NUMERIC: C.UTF-8 LC_TIME: C.UTF-8 The default text search configuration will be set to "english". Data page checksums are disabled. creating directory /var/db/postgres/data19 ... ok creating subdirectories ... ok selecting dynamic shared memory implementation ... posix selecting default "max_connections" ... 100 selecting default "shared_buffers" ... 128MB selecting default time zone ... UTC creating configuration files ... ok running bootstrap script ... ok performing post-bootstrap initialization ... ok syncing data to disk ... ok initdb: warning: enabling "trust" authentication for local connections initdb: hint: 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/data19 -l logfile start </samp></pre> <code>sudo su - postgres</code><br> <code>/usr/local/bin/pg_ctl -D /var/db/postgres/data19 -l logfile start</code> <pre><samp> waiting for server to start.... done server started </samp></pre> <h2>Load Data to PostgreSQL 19</h2> <code>psql</code><br> <code>create user abc password 'abc';</code><br> <code>psql -U postgres -f /usr/local/www/db1_20260808.sql > /usr/local/www/dbname_20260808_load.txt</code> <h2>Restart Server</h2> <code>sudo shutdown -r now</code>
URL:
Operation:
Delete
Update
Insert
Template Prompt