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

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

Related

deleting files in /var/lib/postgresql/12/main while attempting to replication in postresql

I am new to postgres and was following this tutorial for setting Up Physical Streaming Replication with PostgreSQL
In step 3 while running the following command:
sudo -u postgres rm -r /var/lib/postgresql/12/main/*
I was getting the following error
rm: cannot remove '/var/lib/postgresql/12/main/*': No such file or directory
while the /var/lib/postgresql/12/main/ clearly had many files if explored manually.
In desperation, I deleted all the files inside /var/lib/postgresql/12/main/ manually and now any of the further steps are not working.
I have even tried to uninstall and install postgresql-12 using
sudo apt-get --purge remove postgresql
and
sudo apt -y install postgresql-12 postgresql-client-1 respectively
I have even tried doing the whole process again from start and while running the following command:
sudo -u postgres psql
sudo pg_ctlcluster 12 main start
I got this error:
Job for postgresql#12-main.service failed because the service did not take the steps required by its unit configuration.
See "systemctl status postgresql#12-main.service" and "journalctl -xe" for details.
while resolving the above issue using :
sudo chown postgres.postgres /var/lib/postgresql/12/main/global/pg_internal.init
I got this error...
chown: cannot access '/var/lib/postgresql/12/main/global/pg_internal.init': No such file or directory
I think this is happening because of the manual deletion of all the files and folder in
/var/lib/postgresql/12/main/
Any help is much appreciated
Thanks
The glob * is evaluated by your regular user before the sudo is invoked, but your regular user can't see into that directory. So what gets sent to the postgres user is an order to remove the file with the literal name of '/var/lib/postgresql/12/main/*', which doesn't exist. You would need to have your shell that evaluated the glob be postgres, so it can see what it is doing before invoking rm. Something like:
sudo -u postgres bash -c 'rm -r /var/lib/postgresql/12/main/*'
For the rest of it, you didn't give enough details to know what is going on, like what was in the logs, or what were the directory listings at the time your command failed.

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

There is no cubedata.h and contrib directory in Postgresql

I has 128-dimensional vectors of float (face recognition issue). To store these vectors I use datatype cube in Postgresql.
This type has limit by default - 100 dim.
In the psql (PostgreSQL) 10.5 (Ubuntu 10.6-0ubuntu0.18.04.1) this limit don't work: I can store my vector without any problems.
But yeasterday one of my machine was updated to PostgreSQL 10.6 and now I receive an error when try to add new cube-vector into my database. Error about too long vector.
To resolve this problem I have to change this limit in the file cubedata.h which is in contrib directory. But I have no this file and such directory at all!
I try install
sudo apt-get install postgresql-contrib
but, I get the message about the newest postgresql-contrib version is already installed.
After I tried to manually download cubedata.h file into the directory of Postgresql (/usr/share/postgresql/10/extension/), but it doesn't help.
My be someone encountered with such problem?
In Ubuntu 18.04.1 cubedata.h included in the postgres-server-dev-10 package from the PostgreSQL official repository. But prebuilt cube.so included in the postgresql-10 package with default limit.
To increase the limit you should recompile cube.so from source. Below the example of code for the Ubuntu.
Add repository:
PG_VER=10.6
source /etc/os-release
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
echo "deb http://apt.postgresql.org/pub/repos/apt/ ${VERSION_CODENAME}-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt-get update
sudo apt-get install -y postgresql-${PG_VER%.*}
Compile cube extension from source:
PG_VER=10.6
sudo apt-get install -y unzip gcc make zlib1g-dev libreadline-dev postgresql-server-dev-${PG_VER%.*} bison flex
wget https://ftp.postgresql.org/pub/source/v${PG_VER}/postgresql-${PG_VER}.tar.bz2 --quiet -O postgresql.tar.bz2
tar xvf postgresql.tar.bz2
cd postgresql-${PG_VER}
./configure
cd contrib/cube
sed -i 's/#define CUBE_MAX_DIM (100)/#define CUBE_MAX_DIM (128)/' cubedata.h
make USE_PGXS=1
sudo make USE_PGXS=1 install
Check result after restart server:
sudo -u postgres psql dbname -c 'CREATE EXTENSION cube'
sudo -u postgres psql dbname -c 'SELECT cube_dim(cube(array(select generate_series(1, 128)))) as dim'

Knowage BI - SQL Server DataSource

I have a question about knowage (opensource BI software - www.knowage-suite.com).
Can anyone tell me how create DataSource with a SQL Server connection?
Regards,
Tomasz
0> put MSSQL JDBC driver into `./<your_knowage_installation_directory>/lib` folder
1> log in (on web-UI) as administrator
2> data source
3> click on red '+' sign
4> give a label and choose your dialect (SQL-Server)
5> fill your credential (need SQLSErver auth, not active directory)
6> insert into JDBC this: `jdbc:sqlserver://<YOUR_SERVER_IP>`
7> insert `com.microsoft.sqlserver.jdbc.SQLServerDriver` as driver
8> create your dataset as a query (remember `use <your_db_name>` at the beginning of your query)
link to MSSQL jdbc drivers
Below are given steps for installing Knowage and setting up DB.
Install MySQL
1.
sudo apt-get install mysql-server
2.
Modified /etc/mysql/mysql.conf.d/mysqld.cnf and changed
from
bind-address = 127.0.0.1
to
bind-address = *
3.
mysql -u root -p
ALTER USER 'root'#'%' IDENTIFIED BY ''mypswd ';
GRANT ALL PRIVILEGES ON * . * TO 'root'#'%' IDENTIFIED BY ''mypswd';
FLUSH PRIVILEGES;
service mysql restart
Install Java
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java8-set-default
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export PATH=$JAVA_HOME/bin:$PATH
Install Knowage
1. Download Knowage
wget http://download.forge.ow2.org/knowage/Knowage-6_2_0-RC-CE-Installer-Unix-20180509.zip
unzip Knowage-6_2_0-RC-CE-Installer-Unix-20180509.zip
2. Create Swap Memory (https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04)
sudo swapon --show
free -h
df -h
sudo fallocate -l 4G /swapfile
ls -lh /swapfile
sudo chmod 600 /swapfile
ls -lh /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
free -h
Setup Knowage
sh Knowage-6_2_0-RC-CE-Installer-Unix-20180509.sh -c
Used existing MySQL DB and it created knowage_ce with following tables.
Add Database Source in conf/server.xml
<Resource name="jdbc/knowage" auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/knowage_ce"
username="root"
password="mypswd"
maxActive="20" maxIdle="10"
maxWait="-1"/>
Download MySQL Connector and copy to lib dir
cp mysql-connector-java-5.1.46.jar /home/babbarkrishan/knowage/Knowage-Server-CE/lib/
start the knowage server in /bin
sh startup.sh
Hope it will resolve your problem.
Regards,
Krishan

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

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