postgres 9.4 can't find compiled pg_rewind library - postgresql

I'm running Postgres 9.4 installed on Ubuntu 16.04.3. Postgres was installed using apt-get, I downloaded the sources and dependencies with apt-get too. I downloaded pg_rewind REL9_4_STABLE branch and built it. When I try to run my pg_rewind command I get the following:
The servers diverged at WAL position 0/6148D50 on timeline 1.
Rewinding from Last common checkpoint at 0/5000098 on timeline 1
SQL command failed
CREATE OR REPLACE FUNCTION rewind_support.rewind_support_ls_dir(text, boolean) RETURNS SETOF text AS '$libdir/pg_rewind_support' LANGUAGE C STRICT;
ERROR: could not access file "$libdir/pg_rewind_support": No such file or directory
Failure, exiting
I found the pg_rewind_support.so library file and I placed it in the locations returned by pg_config --libdir and --pkglibdir with no success. I even created a copy without .so extension.
$ls -la $(pg_config --pkglibdir)/pg_rewind_support*
-rw-r--r-- 1 root root 18768 Jul 16 17:59 /usr/lib/postgresql/9.4/lib/pg_rewind_support
-rw-r--r-- 1 root root 18768 Jul 16 17:50 /usr/lib/postgresql/9.4/lib/pg_rewind_support.so
$ls -la $(pg_config --libdir)/pg_rewind_support*
-rw-r--r-- 1 root root 18768 Jul 16 17:59 /usr/lib/x86_64-linux-gnu/pg_rewind_support
-rw-r--r-- 1 root root 18768 Jul 16 17:44 /usr/lib/x86_64-linux-gnu/pg_rewind_support.so
Any ideas how can I make my apt-get installed Postgres recognize the pg_rewind library? I don't want to end up running in production a full postgres that was packaged and built in-house.

In working through this with the OP, the steps to build pg_rewind were:
Download the appropriate PostgreSQL 9.4.18 tarball, unpack.
Download pg_rewind, move into contrib/
Configure PostgreSQL to match the directory layout that Debian/Ubuntu uses:
./configure --libdir=/usr/lib/postgresql/9.4/lib --bindir=/usr/lib/postgresql/9.4/bin
Do a "make" on PostgreSQL.
Do a "make" and a "sudo make install" on pg_rewind.
pg_rewind must be installed on both the source system (so that the .so is available there) and on the target system (so the pg_rewind binary is available there).

Related

postgresql archive permission denied

We have installed postgres v12 on ubuntu 20.04 (with apt install -y postgresql postgresql-contrib) and wish to enable archiving to /data/db/postgres/archive by setting the following in postgresql.conf:
max_wal_senders=2
wal_keep_segments=256
wal_sender_timeout=60s
archive_mode=on
archive_command=cp %p /data/db/postgres/archive/%f
However the postgres service fails to write there:
2022-11-15 15:02:26.212 CET [392860] FATAL: archive command failed with exit code 126
2022-11-15 15:02:26.212 CET [392860] DETAIL: The failed archive command was: archive_command=cp pg_wal/000000010000000000000002 /data/db/postgres/archive/000000010000000000000002
2022-11-15 15:02:26.213 CET [392605] LOG: archiver process (PID 392860) exited with exit code 1
sh: 1: pg_wal/000000010000000000000002: Permission denied
This directory /data/db/postgres/archive/ is owned by the postgres user and when we su postgres we are able to create and delete files without a problem.
Why can the postgresql service (running as postgres) not write to a directory it owns?
Here are the permissions on all the parents of the archive directory:
drwxr-xr-x 2 postgres root 6 Nov 15 14:59 /data/db/postgres/archive
drwxr-xr-x 3 root root 21 Nov 15 14:29 /data/db/postgres
drwxr-xr-x 3 root root 22 Nov 15 14:29 /data/db
drwxr-xr-x 5 root root 44 Nov 15 14:29 /data
2022-11-15 15:02:26.212 CET [392860] DETAIL: The failed archive command was: archive_command=cp pg_wal/000000010000000000000002 /data/db/postgres/archive/000000010000000000000002
So, your archive_command is apparently set to the peculiar string archive_command=cp %p /data/db/postgres/archive/%f.
After the %variables are substituted, the result is passed to the shell. The shell does what it was told, which is to set the (unused) environment variable 'archive_command' to be 'cp', and then tries to execute the file pg_wal/000000010000000000000002, which is not allowed to because it doesn't have the execute bit set.
I don't know how you managed to get such a deformed archive_command, but it didn't come from anything you showed us.

How to prevent docker-compose up from changing folder permissions

I'm running a WSL2 Ubuntu terminal with docker for windows, and every time I run docker-compose up the permissions of the folder that contains the project get changed.
Before running docker-compose:
drwxr-xr-x 12 cesarvarela cesarvarela 4096 Jun 24 15:37 .
After:
drwxr-xr-x 12 999 cesarvarela 4096 Jun 24 15:37
This prevents me from changing git branch, editing files, etc. I have to chown the folder again to my user to do that, but I would like to not having to do this everytime.

Is the server running locally and accepting connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.5432”? in Odoo

After some time the Postgres database stopped working of my live server. I'm working on this server from last 8 months. Now suddenly it's stopped working.
when I try to enter the command, psql produces an error
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
enter image description here
I'm using odoo8.
First, you need to make sure the socket file is located in /var/run/postgresql/.s.PGSQL.5432. To check that
$ cat /var/run/postgresql/.s.PGSQL.5432
if result shows something, then the problem is anything else. But, if file is not there you need to check /tmp dir (specially for OSX Homebrew users)
$ cd /tmp
$ l
total 16
drwxrwxrwt 7 root wheel 224B Mar 11 08:03 .
drwxr-xr-x 6 root wheel 192B Jan 23 18:35 ..
-rw-r--r-- 1 root wheel 65B Nov 7 22:59 .BBE72B41371180178E084EEAF106AED4F350939DB95D3516864A1CC62E7AE82F
srwxrwxrwx 1 shiva wheel 0B Mar 11 08:03 .s.PGSQL.5432
-rw------- 1 shiva wheel 57B Mar 11 08:03 .s.PGSQL.5432.lock
drwx------ 3 shiva wheel 96B Mar 10 17:11 com.apple.launchd.C1tUB2MvF8
drwxr-xr-x 2 root wheel 64B Mar 10 17:10 powerlog
Now, there are two ways you can solve the error
Solution One
You can change the application configuration to see for sockets at /tmp/.s.PGSQL.5432
For Rails Users
# config/database.yml
default: &default
adapter: postgresql
pool: 5
# port:
timeout: 5000
encoding: utf8
# min_messages: warning
socket: /tmp/.s.PGSQL.5432
Solution Two
You can create symlinks to the expected location
$ sudo mkdir /var/pgsql_socket
$ sudo ln /tmp/.s.PGSQL.5432 /var/pgsql_socket/
Then the error should go.
Hope this helps.
Note: Your default socket directory may not be /tmp
Did you update/upgrade your database?
Did you start a docker container that interfered with any of your data-store/socket file locations?
This probably doesn't fit your situation exactly, but maybe it will provide some insight:
Sometimes when you try
sudo systemctl start postgresql.service
and the systemd status says it is started but you still get that error message when trying to connect, try this instead:
sudo pg_ctlcluster <version> <cluster> <action>
which in my case had been
sudo pg_ctlcluster 13 main start

Unable to load/insert kernel module

I am using Ubuntu 16.0.4 LTS running linux kernel 4.4.0 series.
I made some changes to the i2c-ocores code and eeprom driver and built the whole kernel afresh. Then I installed the newly built kernel.
I used the following steps to build the kernel:
1. sudo apt-get source linux-image-$(uname -r)
2. Applied my changes to i2c-ocores and eeprom driver
3. sudo chmod a+x debian/scripts/*
4. sudo chmod a+x debian/scripts/misc/*
5. sudo fakeroot debian/rules clean
6. sudo fakeroot debian/rules editconfigs
a. Checked all the options for i2c driver
7. sudo fakeroot debian/rules binary-headers binary-generic skipabi=true skipmodule=true
8. Installed all the .deb packages created by the build.
After installing new kernel, I rebooted the machine and inserted i2c-ocores and eeprom drivers and they worked fine. But after like four or five reboots, my insertion for these drivers fails. I am using modprobe to insert the modules.
Like for i2c-ocores, I get the following errors:
Aug 18 11:08:14 manik kernel: [ 214.831678] i2c_ocores: disagrees about version of symbol i2c_new_device
Aug 18 11:08:14 manik kernel: [ 214.831682] i2c_ocores: Unknown symbol i2c_new_device (err -22)
Aug 18 11:08:14 manik kernel: [ 214.831700] i2c_ocores: disagrees about version of symbol i2c_del_adapter
Aug 18 11:08:14 manik kernel: [ 214.831701] i2c_ocores: Unknown symbol i2c_del_adapter (err -22)
Aug 18 11:08:14 manik kernel: [ 214.831708] i2c_ocores: disagrees about version of symbol i2c_add_adapter
Aug 18 11:08:14 manik kernel: [ 214.831709] i2c_ocores: Unknown symbol i2c_add_adapter (err -22)
does anyone have any idea what is happening here ? Am I doing something wrong ?
There really isn't enough information in the question to give a definite answer, but I believe I might know the problem.
You are rebuilding an Ubuntu kernel, but not changing the version number. As a result, you are, effectively, overwriting the kernel that came with the system. Somewhere in the process, it is possible that you are getting a mismatch between the kernel you are using and the modules you are trying to load (i.e. - you are getting the vanilla kernel and your custom modules or vice-versa). When that happens, the errors you are seeing might come up.
My best advice for you is to change the appended revision of the kernel to something that contains your name before building. At the very least, that will allow you to see which versions are involved by simply running uname -r.
A few asides:
People offered you to build just the modules. That won't work for two reasons. First, you are replacing existing modules, which means you run the risk that exactly what I think happened would happen. More to the point, however, you say you change the kernel's config. You cannot do that when you build just the modules out of tree.
You are running sudo fakeroot. sudo is a tool that makes your commands run as root. fakeroot is a command that fakes the root environment when the real one isn't available. It makes no sense to run both. As far as I can tell, your best bet is to build with fakeroot and install with sudo.

FAILED TO WRITE PID installing Zookeeper

I am new to Zookeeper and it has being a real issue to install it and run. I am not sure what is wrong in here but I will explain what I've being doing to make it more clear:
1.- I've followed the installation guide provided by Apache. This means download the Zookeeper distribution (stable release) extracted the file and moved into the home directory.
2.- As I am using Ubuntu 12.04 I've modified the .bashrc file including this:
export ZOOKEEPER_INSTALL=/home/myusername/zookeeper-3.4.5
export PATH=$PATH:$ZOOKEEPER_INSTALL/bin
3.- Create a config file on conf/zoo.cfg
tickTime=2000
dataDir=/var/zookeeper
clientPort=2181
and also tried with:
dataDir=/var/log/zookeeper
and
dataDir=/var/bin/zookeeper
4.- When running the start command
zkServer.sh start or `bin/zkServer.sh start` nothing happens and always returns this
JMX enabled by default
Using config: /home/sasuke/zookeeper-3.4.5/bin/../conf/zoo.cfg
mkdir: cannot create directory `/var/zookeeper': Permission denied
Starting zookeeper ... /home/sasuke/zookeeper-3.4.5/bin/zkServer.sh: line 113: /var/zookeeper/zookeeper_server.pid: No such file or directory
FAILED TO WRITE PID
I have Java installed and inside the zookeper directory there is a zookeeper.jar file that I think it's not running.
Checking here on stackoverflow there was a guy that said he could run zookeeper after typing
ssh localhost
But when I try to do it I get this error
ssh: connect to host localhost port 22: Connection refused
Please help. I've being here trying to solve it for too long.
Getting started guide of zookeeper:
http://zookeeper.apache.org/doc/r3.1.2/zookeeperStarted.html
Previous case solved with the shh localhost
Zookeeper: FAILED TO WRITE PID
UPDATE:
The permissions for log are:
drwxr-xr-x 19 root root 4096 Oct 10 07:52 log
and for zookeeper:
drwxr-xr-x 2 zookeeper zookeeper 4096 Mar 23 2012 zookeeper
Should I change any of these?
I have had the same problem. In my case was useful to start Zookeeper and directly specify a configuration file:
/bin/zkServer.sh start conf/zoo.conf
It seems you do not have the required permissions. The /var/log owner is is going to be root. Zookeeper stores the process id and snapshot of data in that directory. The process id of the spawned zookeeper server is stored in a file -zookeeper_server.pid (as of 3.3.6)
If you have root previleges, you could start zookeeper with sudo (root) previleges, it should work but definitely not recommended. Make sure you start zookeeper with the same(or higher) permissions as the owner of the directory.
Create a new directory in your home folder like /home/username/zookeeper-data.
Let dataDir point to that directory and it should work.
The default zookeeper installation (tar extract) comes with the conf file named conf/zoo_sample.cfg while the same extract's bin/zkServer.sh expects the conf file to be called zoo.cfg thereby resulting in a "No such file or dir" and the "failed to write pid" error. So before running zkServer.sh to start or stop zookeeper instance, either:
rename the zoo_sample.cfg in the conf dir to zoo.cfg, or
give the name (and path) to the conf file (as suggested by Ilya Lapitan), or, of course
edit zkServer.sh ;-)
When you create the Directory for dataDir make sure to use the -p option. This will allow subsequent directories to be created as required by the application placing files.
mkdir -p /var/log/zookeeperData
Then set:
dataDir=/var/log/zookeeperData
Seems there's all kinds of reasons this can happen. So many helpful answers here!
For me, I had improper line endings in my zoo.cfg file, and possibly invisible characters, so zookeeper was trying to create directories like /var/zookeeper? and /var/zookeeper\r. Reworking my zoo.cfg a bit fixed it for me, along with deleting zoo_sample.conf.
This happens to me due to low disk space. cause zookeeper cant create pid file inside zookeeper data folder.
I have faced the same issue while starting the zookeeper with this command:
hadoop#ubuntu:~/hadoop/zookeeper/zookeeper-3.4.8$ bin/zkServer.sh
start
ERROR [main] client.ConnectionManager$HConnectionImplementation:
The node /hbase is not in ZooKeeper.
It should have been written by the master. Check the value configured in zookeeper.znode.parent. There could be a mismatch with the one configured in the master.
But running the script as su rectified the issue:
hadoop#ubuntu:~/hadoop/zookeeper/zookeeper-3.4.8$ sudo bin/zkServer.sh
start
ZooKeeper JMX enabled by default Using config:
/home/hadoop/hadoop/zookeeper/zookeeper-3.4.8/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
Go to /usr/local/etc/
You will find zookeeper directory
delete the directory
and restart the server - zkServer start
Change the path give dataDir=/tmp/zookeeper. If it works then its clearly access issues
But its generally not advisable to use tmp directory.
This seems to be an ownership issue; running the following solved this for me.
$ sudo chown -R $USER /var/lib/zookeeper
N.B.
I've outlined my steps below which show the error I was getting (the same as the error in this SO question) and the attempt at trying the solution proposed by a user above, which advised to provide zoo.cfg as an argument.
13:01:29 ✔ ~ :: $ZK/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/Cellar/zookeeper/3.4.14/libexec/bin/../conf/zoo.cfg
Starting zookeeper ... /usr/local/Cellar/zookeeper/3.4.14/libexec/bin/zkServer.sh: line 149: /var/lib/zookeeper/zookeeper_server.pid: Permission denied
FAILED TO WRITE PID
13:01:32 ✘ ~ :: $ZK/bin/zkServer.sh start $ZK/conf/zoo.cfg
ZooKeeper JMX enabled by default
Using config: /usr/local/Cellar/zookeeper/3.4.14/libexec/conf/zoo.cfg
Starting zookeeper ... /usr/local/Cellar/zookeeper/3.4.14/libexec/bin/zkServer.sh: line 149: /var/lib/zookeeper/zookeeper_server.pid: Permission denied
FAILED TO WRITE PID
13:04:45 ✔ /var/lib :: ls -la
total 0
drwxr-xr-x 4 root wheel 128 Apr 19 18:55 .
drwxr-xr-x 27 root wheel 864 Apr 19 18:55 ..
drwxr--r-- 3 root wheel 96 Mar 24 15:07 zookeeper
13:04:48 ✔ /var/lib :: echo $USER
tallamjr
13:06:03 ✔ /var/lib :: sudo chown -R $USER zookeeper
Password:
13:06:44 ✔ /var/lib :: ls -la
total 0
drwxr-xr-x 4 root wheel 128 Apr 19 18:55 .
drwxr-xr-x 27 root wheel 864 Apr 19 18:55 ..
drwxr--r-- 3 tallamjr wheel 96 Mar 24 15:07 zookeeper
13:06:48 ✔ ~ :: $ZK/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/Cellar/zookeeper/3.4.14/libexec/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
REF:
- https://askubuntu.com/questions/6723/change-folder-permissions-and-ownership
For me this solution worked:
I granted the read, write and execute permissions for everyone using the command $sudo chmod 777 foldername for the directory zookeeper by going inside the directory /var (/var/zookeeper).
After executing this command try running the zookeeper. It ran in my case
try to use sudo -E bin/zkServer.sh start