How to upgrade postgres 9.5 with non default data directory and checksum enabled to 10.1? - postgresql

I am trying to upgrade postgres 9.5.4 to 10.1 on Ubuntu 14. The data directory for 9.5.4 is /var/lib/postgresql/data/postgresql0
The steps that I have followed
Install postgres 10.1
ubuntu#van-platform:~/build-target/launcher$sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main"
ubuntu#van-platform:~/build-target/launcher$wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
ubuntu#van-platform:~/build-target/launcher$ OK
ubuntu#van-platform:~/build-target/launcher$sudo apt-get update
...
ubuntu#van-platform:~/build-target/launcher$sudo apt-get install postgresql-10
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
comerr-dev krb5-multidev libgssrpc4 libkadm5clnt-mit9 libkadm5srv-mit9
libkdb5-7
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
libpq-dev libpq5 postgresql-client-10 postgresql-client-common
postgresql-common
Suggested packages:
postgresql-doc-10 locales-all
The following NEW packages will be installed:
postgresql-10 postgresql-client-10
The following packages will be upgraded:
libpq-dev libpq5 postgresql-client-common postgresql-common
4 upgraded, 2 newly installed, 0 to remove and 14 not upgraded.
Need to get 6,595 kB of archives.
After this operation, 26.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg/main libpq-dev amd64 10.1-1.pgdg14.04+1 [241 kB]
Get:2 http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg/main libpq5 amd64 10.1-1.pgdg14.04+1 [157 kB]
Get:3 http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg/main postgresql-common all 188.pgdg14.04+1 [220 kB]
Get:4 http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg/main postgresql-client-common all 188.pgdg14.04+1 [81.5 kB]
Get:5 http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg/main postgresql-client-10 amd64 10.1-1.pgdg14.04+1 [1,282 kB]
Get:6 http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg/main postgresql-10 amd64 10.1-1.pgdg14.04+1 [4,613 kB]
Fetched 6,595 kB in 4s (1,473 kB/s)
Preconfiguring packages ...
(Reading database ... 102799 files and directories currently installed.)
Preparing to unpack .../libpq-dev_10.1-1.pgdg14.04+1_amd64.deb ...
Unpacking libpq-dev (10.1-1.pgdg14.04+1) over (9.5.4-1.pgdg14.04+1) ...
Preparing to unpack .../libpq5_10.1-1.pgdg14.04+1_amd64.deb ...
Unpacking libpq5:amd64 (10.1-1.pgdg14.04+1) over (9.5.4-1.pgdg14.04+1) ...
Preparing to unpack .../postgresql-common_188.pgdg14.04+1_all.deb ...
Leaving 'diversion of /usr/bin/pg_config to /usr/bin/pg_config.libpq-dev by postgresql-common'
Unpacking postgresql-common (188.pgdg14.04+1) over (175.pgdg14.04+1) ...
Preparing to unpack .../postgresql-client-common_188.pgdg14.04+1_all.deb ...
Unpacking postgresql-client-common (188.pgdg14.04+1) over (175.pgdg14.04+1) ...
Selecting previously unselected package postgresql-client-10.
Preparing to unpack .../postgresql-client-10_10.1-1.pgdg14.04+1_amd64.deb ...
Unpacking postgresql-client-10 (10.1-1.pgdg14.04+1) ...
Selecting previously unselected package postgresql-10.
Preparing to unpack .../postgresql-10_10.1-1.pgdg14.04+1_amd64.deb ...
Unpacking postgresql-10 (10.1-1.pgdg14.04+1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for ureadahead (0.100.0-16) ...
Setting up libpq5:amd64 (10.1-1.pgdg14.04+1) ...
Setting up libpq-dev (10.1-1.pgdg14.04+1) ...
Setting up postgresql-client-common (188.pgdg14.04+1) ...
Installing new version of config file /etc/postgresql-common/user_clusters ...
Setting up postgresql-common (188.pgdg14.04+1) ...
Configuration file '/etc/logrotate.d/postgresql-common'
==> File on system created by you or by a script.
==> File also in package provided by package maintainer.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** postgresql-common (Y/I/N/O/D/Z) [default=N] ? Y
Installing new version of config file /etc/logrotate.d/postgresql-common ...
Replacing config file /etc/postgresql-common/createcluster.conf with new version
* Starting PostgreSQL 9.5 database server [ OK ]
Setting up postgresql-client-10 (10.1-1.pgdg14.04+1) ...
Setting up postgresql-10 (10.1-1.pgdg14.04+1) ...
Creating new PostgreSQL cluster 10/main ...
/usr/lib/postgresql/10/bin/initdb -D /var/lib/postgresql/10/main --auth-local peer --auth-host md5
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.
fixing permissions on existing directory /var/lib/postgresql/10/main ... 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
Success. You can now start the database server using:
/usr/lib/postgresql/10/bin/pg_ctl -D /var/lib/postgresql/10/main -l logfile start
Ver Cluster Port Status Owner Data directory Log file
10 main 5433 down postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log
* Starting PostgreSQL 10 database server [ OK ]
Processing triggers for libc-bin (2.19-0ubuntu6.13) ...
Create the new data directory
support#vrni-platform:~$ sudo -H -u postgres mkdir -p /var/lib/postgresql/10/data/postgresql0
Stop postgres
ubuntu#vrni-platform:~/build-target/launcher$ sudo service postgresql stop
* Stopping PostgreSQL 10 database server [ OK ]
* Stopping PostgreSQL 9.5 database server [ OK ]
Enable Checksum
support#vrni-platform:/tmp$ sudo -H -u postgres /usr/lib/postgresql/10/bin/pg_ctl -D /var/lib/postgresql/10/data/postgresql0 initdb -o '--data-checksums'
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 enabled.
fixing permissions on existing directory /var/lib/postgresql/10/data/postgresql0 ... 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/lib/postgresql/10/bin/pg_ctl -D /var/lib/postgresql/10/data/postgresql0 -l logfile start
On trying to check for upgrade viability with the below command
sudo -H -u postgres /usr/lib/postgresql/10/bin/pg_upgrade \
-b /usr/lib/postgresql/9.5/bin \
-B /usr/lib/postgresql/10/bin \
-d /var/lib/postgresql/data/postgresql0 \
-D /var/lib/postgresql/10/data/postgresql0 \
-o ' -c config_file=/etc/postgresql/9.5/main/postgresql.conf' \
-O ' -c config_file=/etc/postgresql/10/main/postgresql.conf' --check
It is failing with the below error in pg_upgrade_server.log
command: "/usr/lib/postgresql/9.5/bin/pg_ctl" -w -l "pg_upgrade_server.log" -D "/var/lib/postgresql/data/postgresql0" -o "-p 50432 -b -c config_file=/etc/postgresql/9.5/main/postgresql.conf -c listen_addresses='' -c unix_socket_permissions=0700 -c unix_socket_directories='/tmp'" start >> "pg_upgrade_server.log" 2>&1
waiting for server to start....2017-11-14 15:27:31 UTC [16239-1] LOG: database system was shut down at 2017-11-14 15:16:43 UTC
2017-11-14 15:27:31 UTC [16239-2] LOG: MultiXact member wraparound protections are now enabled
2017-11-14 15:27:31 UTC [16238-1] LOG: database system is ready to accept connections
........................................................... stopped waiting
pg_ctl: could not start server
Can someone let me know what I am doing wrong and how can I get around this error?

As answered here
Changing data_directory in postgres.conf for both 9.5 & 10 solved the issue
postgres#me:~$ grep data_dir /etc/postgresql/*/main/postgresql.conf
/etc/postgresql/10/main/postgresql.conf:data_directory = '/var/lib/postgresql/10/data/postgresql0' # use data in another directory
/etc/postgresql/9.5/main/postgresql.conf:data_directory = '/var/lib/postgresql/data/postgresql0' # use data in another directory

Related

PostgreSQL - WSL : won't init

i'm currently developping a Django server where i need a database, Sqlite3 don't seem to handle well my need so i'm trying to use PostgreSQL instead. I'm devellopping on Windows but the server will run on a Linux system once development is done, so i'm trying to use WSL to fit the expected result.
wsl -l -v
NAME STATE VERSION
Ubuntu-22.04 Running 1
I also updated to WSL2, same issue.
My issue is that i can't start the database :
# sudo service postgresql start
No PostgreSQL clusters exist; see "man pg_createcluster"
What i've done so far :
sudo apt update
sudo apt upgrade
sudo apt install postgresql postgresql-contrib
// it s installed
> psql --version
psql (PostgreSQL) 14.2 (Ubuntu 14.2-1ubuntu1)
// no service currently running
> ps aux| grep postgres
root 583 0.0 0.0 15044 1280 tty3 S 08:42 0:00 grep --color=auto postgres
// no cluster ?!?
> sudo service postgresql start
No PostgreSQL clusters exist; see "man pg_createcluster"
// indeed no cluster are created by default
> pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
// but i can t create one
> pg_createcluster 14.2 main
Error: no initdb program for version 14.2 found
> sudo pg_createcluster 14 main
Creating new PostgreSQL cluster 14/main ...
/usr/lib/postgresql/14/bin/initdb -D /var/lib/postgresql/14/main --auth-local peer --auth-host scram-sha-256 --no-instructions
Can't exec "/usr/lib/postgresql/14/bin/initdb": Permission denied at /usr/bin/pg_createcluster line 86.
Error: Could not open /etc/postgresql/14/main/start.conf for writing: Permission denied
Can't exec "/bin/sh": Permission denied at /usr/bin/pg_createcluster line 617.
Error: initdb failed
I also tried : this stackoverflow link
> sudo service --status-all
// ...
[ - ] postgresql
// ...
> sudo ps aux | grep postgres
root 769 0.0 0.0 15044 1284 tty3 S 08:48 0:00 grep --color=auto postgres
I didn't really understand this link : Change some config file that i can't find
And this one that only proposed to reformat my disk.. Link
Following Mark's Link i was able to find a solution.
It seems that WSL2 is required
I tried 2 wsl distro :
Ubuntu-22.04 -> Didn't work even with the guide, maybe it would work on a fresh install.
Ubuntu 20.04.4 LTS -> fresh install worked
# Create the file repository configuration:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
# Import the repository signing key:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
# Update the package lists:
sudo apt-get update
# Install the latest version of PostgreSQL.
# If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql':
sudo apt-get -y install postgresql postgresql-contrib

Why encryption key is not working in Postgresql TDE during install? "Unknown data received from encryption_key_command"

I'm trying to install the Postgresql TDE from Cybertech (https://www.cybertec-postgresql.com/), specifically version 9.6.12.
I followed the entire guide for default installation:
$ wget https://download.cybertec-postgresql.com/postgresql-9.6.12-tde.tar.gz
$ sudo apt-get install libreadline-dev zlibc zlib1g-dev bison flex libssl-dev openssl libperl-dev python-dev
I've created a shell /opt/pg_key.sh with this content:
#!/bin/sh
echo 882fb7c12e80280fd664c69d2d636913
$ chmod +x /opt/pg_key.sh
$ tar xvfz postgresql-9.6.12-tde.tar.gz
$ cd postgresql-9.6.12-tde/
$ ./configure --prefix /usr/local/pgsql/ --with-openssl --with-perl --with-python
$ sudo make install
$ cd contrib/
$ sudo make install
$ sudo chown user:user /usr/local/pgsql/data/
$ initdb -D /usr/local/pgsql/data/ -K /opt/pg_key.sh
I've got an error in this last command:
The files belonging to this database system will be owned by user
"user". 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.
Data encryption is enabled.
fixing permissions on existing directory /usr/local/pgsql/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 ... FATAL: Unknown data received from encryption_key_command
child process exited with exit code 1
initdb: removing contents of data directory "/usr/local/pgsql/data"
Thanks in advance

Is it possible to install postgresql 11 on Ubuntu 14.04?

I'm running on a Ubuntu 14,04 ('trusty') with no possibility to upgrade (a complex website-management platform is dependant upon it), but I'd like to install the latest version of postgresql in parallel... are there any compatibility issues?
Yes, I tried it just now, I followed the guide here: https://gist.github.com/alistairewj/8aaea0261fe4015333ddf8bed5fe91f8
# add postgresql to apt repository
sudo add-apt-repository 'deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main'
# get the signing key and update
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
# install postgresql
sudo apt-get install postgresql-11
# ensure that the server is started by switching to the postgres user
sudo su - postgres
# I didn't do this part since the database was started during install
# and I checked via `psql`
# /usr/lib/postgresql/11/bin/pg_ctl -D /var/lib/postgresql/11/main -l logfile start

pg_config - how to change postgres versions

By default I had postgres 10 versions on my two ubuntu 14 machines, but I installed postgres 9.6 on the two of them.
But on one of them pg_config give me:
VERSION = PostgreSQL 9.6.6
And the other:
VERSION = PostgreSQL 10.1
They have the same libpq-dev packages in:
dpkg -l | grep libpq-dev
libpq-dev 10.1-1.pgdg14.04+1 amd64 header files for libpq5 (PostgreSQL library)
So I was wondering is there a way for me to change the version installed that it gives me postgres 9.6 instead of postgres 10.01? Maybe using the pg_config file?
Tnx,
Tom
update:
on the instance that still shows postgres 10, this is the result(which shows that it is not installed):
ii pgdg-keyring 2017.3 all keyring for apt.postgresql.org
ii postgresql-9.6 9.6.6-1.pgdg14.04+1 amd64 object-relational SQL database, version 9.6 server
ii postgresql-client-9.6 9.6.6-1.pgdg14.04+1 amd64 front-end programs for PostgreSQL 9.6
ii postgresql-client-common 189.pgdg14.04+1 all manager for multiple PostgreSQL client versions
ii postgresql-common 189.pgdg14.04+1 all PostgreSQL database-cluster manager
ii postgresql-contrib-9.6 9.6.6-1.pgdg14.04+1 amd64 additional facilities for PostgreSQL
duplicated: pg_config shows 9.4 instead of 9.3
On: Debian, Ubuntu
the bash /usr/bin/pg_config is setup to look and get the latest /usr/lib/postgresql/*/pg_config --version available
A fast solution, NOT elegant and weak, could be to update it as follow.
Then update env as, e.g.:
export FORCE_PGCONFIG=/usr/lib/postgresql/12/pg_config
/usr/bin/pg_config (updated) :
PGBINROOT="/usr/lib/postgresql/"
#redhat# PGBINROOT="/usr/pgsql-"
# user edit :
if [ -n "$FORCE_PGCONFIG" ]; then
# up to you to set it properly...
LATEST_SERVER_DEV="$FORCE_PGCONFIG";
else
LATEST_SERVER_DEV=`ls -v $PGBINROOT*/bin/pg_config 2>/dev/null|tail -n1`;
fi
# end user edit ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
if [ -n "$LATEST_SERVER_DEV" ]; then
exec "$LATEST_SERVER_DEV" "$#"
else
if [ -x /usr/bin/pg_config.libpq-dev ]; then
exec /usr/bin/pg_config.libpq-dev "$#"
else
echo "You need to install postgresql-server-dev-NN for building a server-side extension or libpq-dev for building a client-side application." >&2
exit 1
fi
fi

Installing mongoimport in a docker image

from my node scripts I need to execute mongoimport via the exec function from child_process. When it comes to the CI tests in the docker image I run into a problem:
/bin/sh: 1: mongoimport: not found
Now I inserted the installation of mongodb in the drone.yml file:
- apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
- echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.2 main" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list
- apt-get update
- apt-get install -d -y mongodb-org-tools
But still mongoimport isn't found. I even added the root / to the PATH variable or made a
find / -name "mongoimport"
Nothing.
Has anyone an idea, how to get mongoimport working in the docker image?
Thank you.
PS.: Here's the output from apt-get:
$ apt-get install -d -y mongodb-org-tools
Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
mongodb-org-tools
0 upgraded, 1 newly installed, 0 to remove and 102 not upgraded.
Need to get 31.4 MB of archives.
After this operation, 135 MB of additional disk space will be used.
Get:1 http://repo.mongodb.org/apt/debian/ jessie/mongodb-org/3.2/main mongodb-org-tools amd64 3.2.14 [31.4 MB]
Fetched 31.4 MB in 1s (28.2 MB/s)
Download complete and in download only mode
Solved: I tried to install the wrong package.
- apt-get install -d -y mongodb-org-tools
It must be
- apt-get install -y mongodb-org
Then automatically the mongodb-org-tools are installed together with some other packages. Now mongoimport can be used
$ find / -name "mongoimport" -ls > out.txt
$ cat out.txt
2038 10588 -rwxr-xr-x 1 root root 10839312 Jun 13 22:30 /usr/bin/mongoimport