Skip to main content

Matching PostgreSQL Client and Server Versions

Hi,

When PostgreSQL server and cluster versions don't match, PostgreSQL doesn't let you to run some functions, therefore you can not use efficiently and can not be advanced on it. To solve this problem you need to upgrade version or follow bellow steps.

You can try all of steps for your development or test environments.

I installed PostgreSQL server and client with different versions to show what is gonna happen If I try to dump. For sure, I can not get pg_dump!

-bash-4.2$ pg_dump -s testdb > testdb_dump.sql
pg_dump: server version: 9.6.3; pg_dump version: 9.2.18
pg_dump: aborting because of server version mismatch

-bash-4.2$ pg_ctl stop -m fast
waiting for server to shut down.... done
server stopped
-bash-4.2$ mv /var/lib/pgsql /tmp/pgsql_cluster_old
mv: cannot move ‘/var/lib/pgsql’ to ‘/tmp/pgsql_cluster_old’: Permission denied

To move pgsql file, need to be root at this moment.

-bash-4.2$ logout
[root@gunce-test tmp]# mv /var/lib/pgsql /tmp/pgsql_cluster_old

Check PostgreSQL packages out and remove exists old version. 

[root@gunce-test pgsql]# yum list installed |grep postgres*
postgresql96.x86_64          9.6.3-1PGDG.rhel7   @pgdg96
postgresql96-contrib.x86_64  9.6.3-1PGDG.rhel7   @pgdg96
postgresql96-libs.x86_64     9.6.3-1PGDG.rhel7   @pgdg96
postgresql96-server.x86_64   9.6.3-1PGDG.rhel7   @pgdg96

I have only version 9.6.

-bash-4.2$ /usr/pgsql-9.6/bin/initdb -D /var/lib/pgsql/9.6/data
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 "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /var/lib/pgsql/9.6/data ... 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/pgsql-9.6/bin/pg_ctl -D /var/lib/pgsql/9.6/data -l logfile start

-bash-4.2$ /usr/pgsql-9.6/bin/pg_ctl -D /var/lib/pgsql/9.6/data -l logfile start
server starting
-bash-4.2$ createdb sailormoon
-bash-4.2$ psql -dsailormoon
psql (9.6.3)
Type "help" for help.

sailormoon=#


As you see PostgreSQL client version is 9.6.3 now.

Next step is restoring old database which we moved to /tmp file in first step. 


Loves,


Comments

Popular posts from this blog

pg_ctl: command not found

Hi, If you can not reach pg_ctl command in bash also you are sure this command exists in your server, check $PATH. -bash-4.2$ echo $PATH /usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin So, the directory of pg_ctl is not seem in PATH. Input directory of pg_ctl and check it then run it.

PostgreSQL Foreign Data Wrappers

Hi all, I would like to mention about generating Foreign Data Wrappers(FDW) on PostgreSQL 9.6. FDW is used for remote access to tables from external data storage. If needed to use remote table in a query, you can use FDW tables. For instance you can get a table from remote database, but there is a condition. The condition is that user should have proper privileges on FDW table. There is two extension for FDW on PostgreSQL. First one is used for accessing PostgreSQL database to PostgreSQL database, called postgres_fdw . Second one is used for accessing PostgreSQL database to different databases (SQL Server, Sysbase) called tds_fdw .  Foreign Data Wrappers feature lets you to cross-query between remote database tables. Postgres_fdw and tds_fdw has different structure. Tds_fdw usign Tabular Data Stream application layer protocol to transfer data between database server and client. Generating Tds_fdw and Postgres_fdw is similar. I share an example for generating FDW between tw...

PostgreSQL High Availability - Patroni 2

Patroni kurulumuyla ilgili oldukça fazla kaynak bulunmakta fakat kurulum ve yönetimini beraber barındıran kaynağa denk gelmedim. Bu yazıda hem Patroni kurulumu hem de kurulum sonrası yönetimiyle alakalı detaylara ulaşabilirsiniz. PostgreSQL cluster'larının yönetimi için kullanılan Patroni ile ilgili temel bilgilerin yer aldığı Autofailover üzerine hazırladığım yazı serisine aşağıdaki linklerden erişebilirsiniz. PostgreSQL ve Autofailover PostgreSQL'de Autofailover ve Patroni 1 (Giriş) PostgreSQL'de Autofailover ve Patroni 2 (Kurulum, Konfigürasyon ve Yönetim) PostgreSQL'de Autofailover ve Patroni 3 (Mevcut PostgreSQL Cluster'inin Patroni'ye Geçirilmesi) Patroni, PostgreSQL veritabanlarının kurulumundan ve konfigürasyonundan sorumludur. Yani Patroni'yi kurduğumuz sunucular aynı zamanda Patroni ile kurulmuş PostgreSQL'leri barındıracak. Üç node'lu PostgreSQL ve üç node'lu ETCD cluster'larını oluşturacağım. Kuruluma önce üç no...