cstore_fdw extension: FATAL: could not access file "‘cstore_fdw’": No such file or directory - postgresql

I've installed the cstore_fdw extension in PostgreSQL 9.3.5 on OS X, and it looks as though there was no error in the process (/usr/local/pgsql/bin/ is incorrect path, but files were copied where they should be, as pg_config is symlinked in the $PATH):
XXX:cstore_fdw kjedrzejewski$ sudo PATH=/usr/local/pgsql/bin/:$PATH make install
/bin/sh /usr/local/Cellar/postgresql/9.3.5_1/lib/pgxs/src/makefiles/../../config/install-sh -c -d '/usr/local/Cellar/postgresql/9.3.5_1/lib'
/bin/sh /usr/local/Cellar/postgresql/9.3.5_1/lib/pgxs/src/makefiles/../../config/install-sh -c -d '/usr/local/Cellar/postgresql/9.3.5_1/share/postgresql/extension'
/bin/sh /usr/local/Cellar/postgresql/9.3.5_1/lib/pgxs/src/makefiles/../../config/install-sh -c -d '/usr/local/Cellar/postgresql/9.3.5_1/share/postgresql/extension'
/usr/bin/install -c -m 755 cstore_fdw.so '/usr/local/Cellar/postgresql/9.3.5_1/lib/cstore_fdw.so'
/usr/bin/install -c -m 644 ./cstore_fdw.control '/usr/local/Cellar/postgresql/9.3.5_1/share/postgresql/extension/'
/usr/bin/install -c -m 644 ./cstore_fdw--1.3.sql ./cstore_fdw--1.2--1.3.sql ./cstore_fdw--1.1--1.2.sql ./cstore_fdw--1.0--1.1.sql '/usr/local/Cellar/postgresql/9.3.5_1/share/postgresql/extension/'
XXX:cstore_fdw kjedrzejewski$
However, when I try to start Postgres, the extension cannot be loaded:
XXX:cstore_fdw kjedrzejewski$ pg_ctl -D /usr/local/var/postgres start
server starting
XXX:cstore_fdw kjedrzejewski$ FATAL: could not access file "‘cstore_fdw’": No such file or directory
Has anyone got any idea what may be wrong?

It looks like the quotes around your config value are smart quotes? They need to be normal quotes:
shared_preload_libraries='cstore_fdw'

Related

Centos 7 sudo -u <user> mkdir -p <path> stopped working

I have an odd issue where as of recently I am unable to run mkdir -p for a different user running as root and get the following error:
[root#ip-192-168-1-146 ~]# sudo -u myuser mkdir -p /some/target/path
sudo: mkdir -p: command not found
When I test as the 'myuser' user the mkdir -p command works fine. I have additionally tried the following without success:
su - myuser -c "mkdir -p /some/target/path"
sudo -u myuser -i mkdir -p /some/target/path
sudo -u myuser -i -c "mkdir -p /some/target/path" <---dont think syntax is right on this but tried anyways.
Context: I am executing a script to setup my AWS EC2 instance that populates all defined directories. This has been working fine until recently. Not including my script here as the above command doesn't work by itself.
Env output for 'mysuser':
$ env
XDG_SESSION_ID=1
HOSTNAME=ip-192-168-1-146.ec2.internal
SHELL=/bin/bash
TERM=xterm-256color
HISTSIZE=1000
USER=myuser
LS_COLORS=rs=0:di=38;5;27:ln=38;5;51:mh=44;38;5;15:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=05;48;5;232;38;5;15:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;34:*.tar=38;5;9:*.tgz=38;5;9:*.arc=38;5;9:*.arj=38;5;9:*.taz=38;5;9:*.lha=38;5;9:*.lz4=38;5;9:*.lzh=38;5;9:*.lzma=38;5;9:*.tlz=38;5;9:*.txz=38;5;9:*.tzo=38;5;9:*.t7z=38;5;9:*.zip=38;5;9:*.z=38;5;9:*.Z=38;5;9:*.dz=38;5;9:*.gz=38;5;9:*.lrz=38;5;9:*.lz=38;5;9:*.lzo=38;5;9:*.xz=38;5;9:*.bz2=38;5;9:*.bz=38;5;9:*.tbz=38;5;9:*.tbz2=38;5;9:*.tz=38;5;9:*.deb=38;5;9:*.rpm=38;5;9:*.jar=38;5;9:*.war=38;5;9:*.ear=38;5;9:*.sar=38;5;9:*.rar=38;5;9:*.alz=38;5;9:*.ace=38;5;9:*.zoo=38;5;9:*.cpio=38;5;9:*.7z=38;5;9:*.rz=38;5;9:*.cab=38;5;9:*.jpg=38;5;13:*.jpeg=38;5;13:*.gif=38;5;13:*.bmp=38;5;13:*.pbm=38;5;13:*.pgm=38;5;13:*.ppm=38;5;13:*.tga=38;5;13:*.xbm=38;5;13:*.xpm=38;5;13:*.tif=38;5;13:*.tiff=38;5;13:*.png=38;5;13:*.svg=38;5;13:*.svgz=38;5;13:*.mng=38;5;13:*.pcx=38;5;13:*.mov=38;5;13:*.mpg=38;5;13:*.mpeg=38;5;13:*.m2v=38;5;13:*.mkv=38;5;13:*.webm=38;5;13:*.ogm=38;5;13:*.mp4=38;5;13:*.m4v=38;5;13:*.mp4v=38;5;13:*.vob=38;5;13:*.qt=38;5;13:*.nuv=38;5;13:*.wmv=38;5;13:*.asf=38;5;13:*.rm=38;5;13:*.rmvb=38;5;13:*.flc=38;5;13:*.avi=38;5;13:*.fli=38;5;13:*.flv=38;5;13:*.gl=38;5;13:*.dl=38;5;13:*.xcf=38;5;13:*.xwd=38;5;13:*.yuv=38;5;13:*.cgm=38;5;13:*.emf=38;5;13:*.axv=38;5;13:*.anx=38;5;13:*.ogv=38;5;13:*.ogx=38;5;13:*.aac=38;5;45:*.au=38;5;45:*.flac=38;5;45:*.mid=38;5;45:*.midi=38;5;45:*.mka=38;5;45:*.mp3=38;5;45:*.mpc=38;5;45:*.ogg=38;5;45:*.ra=38;5;45:*.wav=38;5;45:*.axa=38;5;45:*.oga=38;5;45:*.spx=38;5;45:*.xspf=38;5;45:
MAIL=/var/spool/mail/myuser
PATH=/sbin:/bin:/opt/home/myuser/.local/bin:/opt/home/myuser/bin
PWD=/opt/home/myuser
LANG=en_US.UTF-8
HISTCONTROL=ignoredups
SHLVL=1
HOME=/opt/home/myuser
LOGNAME=myuser
LESSOPEN=||/usr/bin/lesspipe.sh %s
_=/bin/env
Env output for 'root':
$ env
XDG_SESSION_ID=1
HOSTNAME=ip-192-168-1-146.ec2.internal
SHELL=/bin/bash
TERM=xterm-256color
HISTSIZE=1000
USER=root
LS_COLORS=rs=0:di=38;5;27:ln=38;5;51:mh=44;38;5;15:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=05;48;5;232;38;5;15:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;34:*.tar=38;5;9:*.tgz=38;5;9:*.arc=38;5;9:*.arj=38;5;9:*.taz=38;5;9:*.lha=38;5;9:*.lz4=38;5;9:*.lzh=38;5;9:*.lzma=38;5;9:*.tlz=38;5;9:*.txz=38;5;9:*.tzo=38;5;9:*.t7z=38;5;9:*.zip=38;5;9:*.z=38;5;9:*.Z=38;5;9:*.dz=38;5;9:*.gz=38;5;9:*.lrz=38;5;9:*.lz=38;5;9:*.lzo=38;5;9:*.xz=38;5;9:*.bz2=38;5;9:*.bz=38;5;9:*.tbz=38;5;9:*.tbz2=38;5;9:*.tz=38;5;9:*.deb=38;5;9:*.rpm=38;5;9:*.jar=38;5;9:*.war=38;5;9:*.ear=38;5;9:*.sar=38;5;9:*.rar=38;5;9:*.alz=38;5;9:*.ace=38;5;9:*.zoo=38;5;9:*.cpio=38;5;9:*.7z=38;5;9:*.rz=38;5;9:*.cab=38;5;9:*.jpg=38;5;13:*.jpeg=38;5;13:*.gif=38;5;13:*.bmp=38;5;13:*.pbm=38;5;13:*.pgm=38;5;13:*.ppm=38;5;13:*.tga=38;5;13:*.xbm=38;5;13:*.xpm=38;5;13:*.tif=38;5;13:*.tiff=38;5;13:*.png=38;5;13:*.svg=38;5;13:*.svgz=38;5;13:*.mng=38;5;13:*.pcx=38;5;13:*.mov=38;5;13:*.mpg=38;5;13:*.mpeg=38;5;13:*.m2v=38;5;13:*.mkv=38;5;13:*.webm=38;5;13:*.ogm=38;5;13:*.mp4=38;5;13:*.m4v=38;5;13:*.mp4v=38;5;13:*.vob=38;5;13:*.qt=38;5;13:*.nuv=38;5;13:*.wmv=38;5;13:*.asf=38;5;13:*.rm=38;5;13:*.rmvb=38;5;13:*.flc=38;5;13:*.avi=38;5;13:*.fli=38;5;13:*.flv=38;5;13:*.gl=38;5;13:*.dl=38;5;13:*.xcf=38;5;13:*.xwd=38;5;13:*.yuv=38;5;13:*.cgm=38;5;13:*.emf=38;5;13:*.axv=38;5;13:*.anx=38;5;13:*.ogv=38;5;13:*.ogx=38;5;13:*.aac=38;5;45:*.au=38;5;45:*.flac=38;5;45:*.mid=38;5;45:*.midi=38;5;45:*.mka=38;5;45:*.mp3=38;5;45:*.mpc=38;5;45:*.ogg=38;5;45:*.ra=38;5;45:*.wav=38;5;45:*.axa=38;5;45:*.oga=38;5;45:*.spx=38;5;45:*.xspf=38;5;45:
MAIL=/var/spool/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
PWD=/root
LANG=en_US.UTF-8
HISTCONTROL=ignoredups
SHLVL=1
HOME=/root
LOGNAME=root
LESSOPEN=||/usr/bin/lesspipe.sh %s
_=/bin/env
mkdir is on the system:
[root#ip-192-168-1-146 ~]# ls /bin/mkdir
/bin/mkdir
[root#ip-192-168-1-146 ~]# which mkdir
/bin/mkdir
[myuser#ip-192-168-1-146 ~]$ which mkdir
/bin/mkdir
I am at a loss, if anyone has any suggestions I'ld be greatful. Again this has been working for few months now.
Thanks!
so...no idea how it happened but somehow I pasted a special character M-BM- in place of a proper space char.
The M-BM- characters are an ASCII representation of byte sequence 0xc2 0xa0, which is the UTF8 encoding of unicode character A0 - a non-breaking space character. This character can be inserted in both LibreOffice and Microsoft Word documents using the key sequence Ctrl+Shift+SPACE.
¯\(ツ)/¯

PostgreSQL pg_basebackup missing toc.dat header file

I'm using the following command to backup my database (PostgreSQL 11.8):
pg_basebackup -D "C:\\temp" -F tar -X f -z -P -U myUser
And the following to restore:
I manually unpack the base.tar.gz => base.tar
pg_restore -h localhost -W -U myUser -c -C -d myDatabase -F tar -v "C:\\temp\\base.tar"
This results in the following error:
pg_restore: [tar archiver] could not find header for file "toc.dat" in tar archive
What am I doing wrong?
Also, I tried different versions of the restore (only data, etc.) but of course the missing header file issue persists.
Thanks for your help!
You cannot use pg_basebackup and pg_restore together:
pg_basebackup is a physical backup tool
pg_restore can only be used with a logical backup created by pg_dump.
There is no single PostgreSQL command to restore a backup created with pg_basebackup.
To restore a physical backup see https://www.postgresql.org/docs/12/continuous-archiving.html#BACKUP-PITR-RECOVERY

How to run the python application and postgres in one docker container?

I have a python application that interacts with the postgresql database and i need to run it all in one docker container.
I get a connection error when running the container:
...
File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
return fut.result()
File "/usr/lib/python3.6/asyncio/base_events.py", line 787, in create_connection
', '.join(str(exc) for exc in exceptions)))
OSError: Multiple exceptions: [Errno 111] Connect call failed ('::1', 5432), [Errno 111] Connect call failed ('127.0.0.1', 5432)
My Dockerfile:
FROM postgres:10.0-alpine
RUN apk add --update --no-cache g++ alpine-sdk
RUN apk --no-cache add python3-dev
RUN apk add --no-cache python3 && \
python3 -m ensurepip && \
rm -r /usr/lib/python*/ensurepip && \
pip3 install --upgrade pip setuptools && \
if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \
if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \
rm -r /root/.cache
ADD app /app/
RUN chmod -R 777 /app
WORKDIR /app
ADD requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
USER postgres
RUN chmod 0700 /var/lib/postgresql/data &&\
initdb /var/lib/postgresql/data &&\
echo "host all all 0.0.0.0/0 md5" >> /var/lib/postgresql/data/pg_hba.conf &&\
echo "listen_addresses='*'" >> /var/lib/postgresql/data/postgresql.conf &&\
pg_ctl start &&\
psql --command "ALTER USER postgres WITH ENCRYPTED PASSWORD 'postgres';"
EXPOSE 5432
EXPOSE 80
CMD ["python3", "main.py"]
Although this is not recommended, it's doable. The problem is pg_ctl in RUN instruction is executed at build time, not in the container. You need to run it with CMD.
You can have a script like
pg_ctl start
psql --command "ALTER USER postgres WITH ENCRYPTED PASSWORD 'postgres';"
python3 main.py
COPY the script in the image and at the end of the dockerfile, `CMD ["./script.sh"]
#Anton, it is not recommended to run multiple processes inside a docker container. Have a look at this link https://docs.docker.com/config/containers/multi-service_container/ it will explain more and demonstrate a manner to accomplish this. You probably are aware, but your container will be running the postgresql instance and have the data in it, so if you ever re-create the container, you will lose any data in that container.

Restart postgres in a docker environment

I have troubles restarting a dockerized postgres database (I use Core OS). The database is started in a bash script using the command
# boot.sh
sudo -i -u postgres /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf
which works. I have another script called by confd which is run when some etcd keys change (this part is ok, the file is correctly called) and must restart postgres (not reload, because some config changes require a restart). Here are the main options I tried, which failed...
# restart.sh
sudo -u postgres /usr/lib/postgresql/9.3/bin/pg_ctl --pgdata=/var/lib/postgresql/9.3/main restart
systematically raises an error:
%FATAL: lock file "postmaster.pid" already exists
%HINT: Is another postmaster (PID 273) running in data directory "/var/lib/postgresql/9.3/main"?
Furthermore,
# restart.sh
rm /var/lib/postgresql/9.3/main/postmaster.pid
sudo -i -u postgres /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf
,
rm /var/lib/postgresql/9.3/main/postmaster.pid
/etc/init.d/postgresql start
,
/etc/init.d/postgresql restart
and
exec su postgres -c "/usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf"
fail with
ERROR exit status 1
Any thought? Thank you in advance!
For me, changing the config and doing
$ docker restart <postgres_container>
on the host works just fine.

Postgres cannot see my PGDATA environment variable

Can anyone explain this:
~$ echo $PGDATA
/Library/PostgreSQL/9.2/data
~$ cd /Library/PostgreSQL/9.2/
/Library/PostgreSQL/9.2$ sudo su postgres
bash-3.2$ echo $PGDATA
<blank line>
bash-3.2$ pg_ctl start
pg_ctl: no database directory specified and environment variable PGDATA unset
Try "pg_ctl --help" for more information.
bash-3.2$ export PGDATA="/Library/PostgreSQL/9.2/data"
bash-3.2$ pg_ctl start
server starting
bash-3.2$
The following is in my ~/.bashrc file:
export PGDATA="/Library/PostgreSQL/9.2/data"
I'm not mis-spelling the path in PGDATA:
~$ echo $PGDATA
/Library/PostgreSQL/9.2/data
export PGDATA="/Library/PostgreSQL/9.2/data"
sudo can't be assumed to keep the environment variables of its caller.
See its manpage for the details with your specific OS.
As far as I know, environment variables are attached to a shell, and as far as I can tell I'm in the same shell.
This works for me:
~$ cd /Library/PostgreSQL/9.2/
/Library/PostgreSQL/9.2$ sudo -E su postgres
...
-E The -E (preserve environment) option will override the
env_reset option in sudoers(5)). It is only available when
either the matching command has the SETENV tag or the
setenv option is set in sudoers(5).
I only understand the following:
The -E (preserve environment) option
Next comment:
When I su to postgres I do su - postgres. Notice the hyphen.
Here is what my man pages say about the hyphen:
-l Simulate a full login. The environment is discarded except for
HOME, SHELL, PATH, TERM, and USER. HOME and SHELL are modified
as above. USER is set to the target login. PATH is set to
``/bin:/usr/bin''. TERM is imported from your current environ-
ment. The invoked shell is the target login's, and su will
change directory to the target login's home directory.
- (no letter) The same as -l.
I don't see how that will preserve the PGDATA environment variable, and this is what happened when I tried the hyphen:
/Library/PostgreSQL/9.2$ sudo su - postgres
Password:
7studs-computer:~ postgres$ ls
bin pgAdmin3.app
data pg_env.sh
doc scripts
include share
installer stackbuilder.app
lib uninstall-postgresql.app
7studs-computer:~ postgres$ pg_ctl start
-bash: pg_ctl: command not found
7studs-computer:~ postgres$ ls
bin pgAdmin3.app
data pg_env.sh
doc scripts
include share
installer stackbuilder.app
lib uninstall-postgresql.app
7studs-computer:~ postgres$ cd bin
7studs-computer:bin postgres$ ls
clusterdb pg_config pgbench
createdb pg_controldata pltcl_delmod
createlang pg_ctl pltcl_listmod
createuser pg_dump pltcl_loadmod
dropdb pg_dumpall postgres
droplang pg_receivexlog postmaster
dropuser pg_resetxlog psql
ecpg pg_restore reindexdb
initdb pg_standby vacuumdb
oid2name pg_test_fsync vacuumlo
pg_archivecleanup pg_test_timing
pg_basebackup pg_upgrade
7studs-computer:bin postgres$ ./pg_ctl start
pg_ctl: no database directory specified and environment variable PGDATA unset
Try "pg_ctl --help" for more information.
7studs-computer:bin postgres$
So the hyphen doesn't work for me (OSX 10.6.8).