Postgres 13 fails at the initdb stage - postgresql

I've followed the official installation instructions for my Centos 7 machine:
# Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# Install PostgreSQL:
sudo yum install -y postgresql13-server
# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
sudo systemctl enable postgresql-13
sudo systemctl start postgresql-13
The issue comes at the initdb stage. Instead of getting the typical "OK" at the end of execution, I'm given nothing. After looking through the postgresql-13-setup script, I managed to find an ouput log at /var/lib/pgsql/13/initdb.log:
/usr/pgsql-13/bin/initdb: error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory
It looks like, for whatever reason, libpq.so.5 (which is present in other past postgres installs) is missing from /usr/pgsql-13/lib/.
I've tried uninstalling/reinstalling postgres-13 multiple times now, clearing out the service, deleting all the directories, etc. This issue is only happening in this specific machine (I've installed postgres 13 in various other similar machines with no issue).
edit:
Ad requested, running:
/usr/pgsql-13/bin/initdb -E UTF8 /var/lib/pgsql/13/data
Returns the same exact error:
/usr/pgsql-13/bin/initdb: error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory

Related

Citus 10.2 not starting an instance of PostgreSQL

I'm using RHEL 8.4 and I followed the installation instruction at Set up a single-node Citus cluster on your own Linux machine from RPM packages..
Step 1 and 2 (Install PostgreSQL 14 and the Citus extension and Initialize the Cluster) went through without any issues.
But When I tried (Step 3: Start the database server)
pg_ctl -D citus -o "-p 9700" -l citus_logfile start
I got the following error in terminal
waiting for server to start.... stopped waiting
pg_ctl: could not start server
Examine the log output.
The log output
FATAL: could not access file "citus": No such file or directory
LOG: database system is shut down
I do have a directory 'citus' in postgres user's home directory with all required files in it along with postgresql.conf
Kindly help.
It appears you ran into one of 2 issues:
Possible issue #1:
You did not successfully install citus package and the citus.so file is missing.
Can you see the file /usr/pgsql-14/lib/citus.so that should be installed via the package citus102_14?
If that is not the case, you should figure out why the package is not installed.
Possible issue #2
You do not run pg_ctl command in the home directory of postgres user.
I was getting the same error. I am using the Postgres compiled from the source file. Thus, instead of
sudo apt-get -y install postgresql-14-citus-10.2
I compiled the source of the Citus from Github and specified the path to location of my Postgres while configuring as:
git clone https://github.com/citusdata/citus.git
cd citus
./configure --prefix=/usr/local/pgsql/
make
sudo make install
I do not get an error during pg_ctl start and I can load extension as CREATE EXTENSION citus;.

Installing postgresql on CentOS 5.5 postgresql-setup initdb command not found error

I was following these steps to install postgresql and then odoo v9 :
https://www.odoo.com/documentation/9.0/setup/install.html
Basically it follows these steps outlined here:
https://www.odoo.com/forum/help-1/question/issue-while-installing-following-the-instructions-for-packaged-installers-rpm-93756
I get exactly the same situation. The first steps go through without issue but then the postgresql-setup initdb command cannot be found.
I have root access to the server and I know it's running centOS5.5. How can I troubleshoot this? I believe I installed the 9.4 version but when I do psql -V I get the server has v8.3.
I ran some commands on the server and here are the results:
postgresql-setup initdb
command cannot be found
postgres
root execution is not permitted, server must be restarted as underprivileged id...
initdb
no data directory specified, you must identify dir where datase system will reside
locate postgresql
i get an .rb, .xml and .yml files
locate psql
/usr/lib64 - a few libodbcpsql.so files
pqsl -V
8.1.23
I get command not found for all other commands in the list of commands to install odoo up until sudo yum config manager --add-repo etc...
sudo su postgres -c "psql -c 'show data_directory'"
could not change directory to 'the directory im currently in on my server'

How to install PostgreSQL on OSX Yosemite using MacPorts

I want to install PostgreSQL for a node project that I'm developing in OSX Yosemite. I use MacPorts and so tried the method described here: https://github.com/codeforamerica/ohana-api/wiki/Installing-PostgreSQL-with-MacPorts-on-OS-X
...but I get an error during step 2:
$ sudo gem install pg -- --with-pg-config=/opt/local/lib/postgresql93/bin/pg_config > ruby_error
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --with-pg-config=/opt/local/lib/postgresql93/bin/pg_config
Using config values from /opt/local/lib/postgresql93/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
...thinking that I may not need to install the pg gem since I want to work with Node and not Ruby, I moved on to the next steps. But there I run into an error during step 3.3:
$ sudo su postgres -c '/opt/local/lib/postgresql93/bin/initdb -D /opt/local/var/db/postgresql93/defaultdb'
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
could not identify current directory: Permission denied
could not identify current directory: Permission denied
could not identify current directory: Permission denied
The program "postgres" is needed by initdb but was not found in the
same directory as "initdb".
Check your installation.
...checking my /opt/local/lib/postgresql93/bin/ directory, I see both initdb and postgres. I see those lines saying Permission denied and am wondering what that's about.
Not sure how to progress. Thinking of using Postgres.app if it really is easier but not sure whether it would be better to install using MacPorts since I install most other things using MacPorts. Tips about any of my problems are appreciated!
The permissions/ownership on the directories between / and defaultdb likely need to be fixed. I think PostgreSQL can be sensitive to ownership of these, though it seems that in your case PostgreSQL simply doesn't have access to those. This is what I have for each directory.
$ ls -hlt /opt/local/var/db/
total 0
drwxr-xr-x 7 root admin 238B Jan 23 16:54 texmf
drwxr-xr-x 3 root admin 102B Dec 25 07:37 postgresql94
You could fix permissions by doing sudo chmod a+rx /opt/local/var/db/ as needed.
For the defaultdb directory itself, you should follow the instructions that you link to, which seem to have the same as I have:
sudo chown postgres:postgres /opt/local/var/db/postgresql93/defaultdb
Below are instructions adapted from my blog (though I recommend using PostgreSQL 9.4, which I now do). I've been running PostgreSQL using MacPorts since 9.1 without major problems.
1. Install PostgreSQL using MacPorts.
Of course, I assume you’ve got MacPorts up and running on your system.
sudo port install postgresql93 +perl +python27
sudo port install postgresql93-server
2. Set up PostgreSQL
I first need to initialize the database cluster and then get the server running. The following comes straight from the on-screen instructions supplied with the MacPorts port postgresql93-server.
sudo mkdir -p /opt/local/var/db/postgresql93/defaultdb
sudo chown postgres:postgres /opt/local/var/db/postgresql93/defaultdb
sudo su postgres -c '/opt/local/lib/postgresql93/bin/initdb -D /opt/local/var/db/postgresql93/defaultdb'
Note that MacPorts creates a launch daemon. To load it now and to make sure it launches on system start, do:
sudo defaults write /Library/LaunchDaemons/org.macports.postgresql93-server.plist Disabled -bool false
sudo launchctl load /Library/LaunchDaemons/org.macports.postgresql93-server.plist
I then use psql for some set-up to get my database going.
sudo su - postgres
/opt/local/lib/postgresql93/bin/psql -U postgres -d template1
If you get to here, then you have PostgreSQL running on your system.
I had the same issue when attempting to run initdb, even when following the description by Ian Gow:
$ sudo su postgres -c '/opt/local/lib/postgresql94/bin/initdb -D /opt/local/var/db/postgresql94/defaultdb'
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
could not identify current directory: Permission denied
could not identify current directory: Permission denied
could not identify current directory: Permission denied
The program "postgres" is needed by initdb but was not found in the
same directory as "initdb".
Check your installation.
Turns out that user postgres cannot do anything if you try to make it run a command from within your own home directory, because in there postgres is not allowed to read its own location and hence cannot figure out any other paths, either. So the simple solution is to run cd / before any command that must be run as postgres (initdb, pg_ctl, etcetera). Afterwards, you can quickly jump back to your previous working directory using cd -.

How to initialize initdb in fedora postgresql

I was installed postgresql on fedora 20 using rpm packages. i was manually downloaded the packages which were required for postgres those packages are as follows:
libxslt-1.1.28-5.fc20.x86_64.rpm postgresql-9.3.1-2.fc20.x86_64.rpm
postgresql93-9.3.4-1PGDG.f20.x86_64.rpm
postgresql93-contrib-9.3.4-1PGDG.f20.x86_64.rpm
postgresql93-libs-9.3.4-1PGDG.f20.x86_64.rpm
postgresql93-server-9.3.4-1PGDG.f20.x86_64.rpm
postgresql-libs-9.3.1-2.fc20.x86_64.rpm uuid-1.6.2-26.el7.x86_64.rpm
and i was installed those packages like this.
[root#fedorarpmpostgres ~]# rpm -ivh libxslt-1.1.28-5.fc20.x86_64.rpm
Output
Preparing... ################################# [100%]
package libxslt-1.1.28-5.fc20.x86_64 is already installed
so its already installed ok now i'm successfull in stalling all this packages. now how can i
install initdb
i tried like this way but i got this error.
[root#fedorarpmpostgres ~]# /usr/pgsql-9.3/bin/initdb --encoding=UTF8 --
Output:
pgdata=/var/lib/pgsql/9.3/data/
initdb: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.
one thing i was to inform you is i'm success in installing postgres through yum but i need postgres installation through rpm only like the way i did above
could any body help me how to initialize initdb.
Thanks.
With your root user, if you haven't set the postgres user password, which is not set by default, do a su postgres and you should be able to do a initdb.

Cannot use commands 'postgres' or 'pg_ctl'

I am on Unix. I have got postgresql-9.3 installed.
When I want to start the server using pg_ctl or postgres, the terminal gives me:
The program 'postgres' is currently not installed. You can install it by typing:
sudo apt-get install postgres-xc
Can't I start the server without this postgres-xc?
This must be remnants of the postgres-xc package you had installed previously.
Since you just installed postgresql-9.3 and don't seem to have any databases in use, yet, I suggest to completely purge all postgres packages.
sudo apt-get purge postgresql-9.2
sudo apt-get purge postgresql-xc
...
Until there's nothing left:
dpkg -l | grep postgres
Then start from scratch. Your instance of pg_ctl seems to belong to the package postgres-xc. This should be gone after you've uninstalled the package. Find out with one of these commands:
dpkg -S pg_ctl
dlocate pg_ctl
apt-file search pg_ctl
pg_ctlcluster is provided by the package postgresql-common.
pg_ctl is provided by the package postgresql-9.3.
More about starting Postgres in the manual.
It is possible you might be missing a few things.
Try:
sudo apt-get install postgresql-client and
sudo apt-get install postgresql postgresql-contrib
The message about installing xc is a dud, it's probably suggesting that based on what it scanned inside the xc repositories.
Here's a good reference to this problem and its solution:
https://dba.stackexchange.com/questions/72580/missing-the-pg-ctl-package-in-postgres-9-3-installation
Due to reasons a normal install of postgres will not place the postgres binary file in the path.
Adding the right directory to the path solves the problem (temporarily).
PATH=/usr/lib/postgresql/9.3/bin:$PATH
To make it permanent on my Ubuntu machine I added the line to /etc/environment this makes it work for all users.
The correct way to set the PATH is different for different systems, for more info see see:
How to permanently set $PATH on Linux?
You must install postgresql-client:
sudo install postgresql-client
Try to enter this command to the console:
sudo -u postgres psql