could not access file "$libdir/plpgsql" while creating template_postgis - postgresql

I have installed PostgreSQL and Postgis on my Mac before when it's 9.3 and 2.1 but never used.
After upgrading pg to 4.5_2 and postgis to 2.2 (the latest now), I try to build my first postgis based app and creating template_postgis like this:
createdb template_postgis
psql -d template_postgis -f /usr/local/share/postgis/postgis.sql
And got this error:
SET
BEGIN
psql:/usr/local/share/postgis/postgis.sql:77: ERROR: could not access file "$libdir/plpgsql": No such file or directory
...
So I run pg_config --libdir it says /usr/local/lib, and pg_config --pkglibdir returns /usr/local/lib/postgresql.
And I found plpgsql.so under pkglibdir not libdir,
so I create a symbol link named plpgsql.so and another plpgsql under libdir, but it still not works.
What really is the problem there? How can I fix this?
My Mac is running the newest OS X 10.11 and both of them are installed and upgraded by homebrew.
Update:
Inspired by #Stefan D. , I run psql -c "\dx" to list all the installed extensions which results:
Name | Version | Schema | Description
---------+---------+------------+---------------------------------------------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
postgis | 2.1.7 | public | PostGIS geometry, geography, and raster spatial types and functions
So I run ALTER EXTENSION postgis UPDATE TO "2.2.0"; to manually update the version of postgis, but got another error: could not open extension control file "/usr/local/Cellar/postgresql/9.4.5/share/postgresql/extension/postgis.control": No such file or directory.
This is wired as my PostgreSQL is installed in /usr/local/Cellar/postgresql/9.4.5_2/. And postgis.control is not listed in /usr/local/Cellar/postgresql/9.4.5_2/share/postgresql/extension/ either.
After locating, I find all the .control files have an symbol link in /usr/local/share/postgresql/extension/.

What a coinincidence: I just had a similar problem and were searching for a solution when I found your question.
I also updated my postgresql/postgis installation a couple of days ago, and when I wanted to use my database (which I created with before the update) it today I got an error similiar to yours (for me it was that the postgis 2.1 library could not be found)
Meanwhile I could fix it. Here is how I did it:
My problem was: The database was set up with the old Postgresql/postgis version. And it still looks for the old libraries. You can check this by listing all your extensions with the following command:
psql --username=gisuser --dbname=gis -c "\dx"
For me this gave me this output:
List of installed extensions
Name | Version | Schema | Description
------------------+---------+------------+---------------------------------------------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
postgis | 2.1.7 | public | PostGIS geometry, geography, and raster spatial types and functions
postgis_topology | 2.1.7 | topology | PostGIS topology spatial types and functions
(3 rows)
As you can see the postgis and postgis_topology extension versions (2.1.7) do not fit my installed versions (2.2.0)
To fix that I executed the following commands to update the extension versions:
psql --username=gisuser --dbname=gis -c "ALTER EXTENSION postgis UPDATE;"
psql --username=gisuser --dbname=gis -c "ALTER EXTENSION postgis_topology UPDATE;"
You will probably have to alter the command a bit (username, database, and the extension you want to update)
Check whether it worked again with:
psql --username=gisuser --dbname=gis -c "\dx"
Now the output is:
List of installed extensions
Name | Version | Schema | Description
------------------+---------+------------+---------------------------------------------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
postgis | 2.2.0 | public | PostGIS geometry, geography, and raster spatial types and functions
postgis_topology | 2.2.0 | topology | PostGIS topology spatial types and functions
(3 rows)
(Note the changed version number for postgis and postgis_topology)

Finally, I got out what caused this issue: Although there's only one postgres installed on my Mac, but there are TWO postgres exits!
What really happened is I have upgraded postgres program without shutting down, neither brew did, so I have a postgres 9.4.5_2 installed locally, and an old one in the memory!
So the solutions is really simple: Shutting down the old one and start the new installed postgres!
Anyway, thanks for your kind help!

Probably You have installed multipe instances of Postgres on Your Mac.
When you execute pg_config --pkglibdir, make sure it's the one associated with your installation. Run:
which pg_config

Related

How to fix "extension has no installation script nor update path" error?

I'm maintaining an old PostgreSQL extension, and trying to release a new version. The test script fails when running CREATE EXTENSION IF NOT EXISTS table_version version '1.10.3';:
ERROR: extension "table_version" has no installation script nor update path for version "1.10.3"
It is not this issue, because the package (installed successfully in an earlier step in the test script) does contain the relevant /usr/share/postgresql/10/extension/table_version--1.10.3.sql file. I'm stumped for what else could be the issue.
To reproduce:
Run nix-shell --pure --run 'docker build --tag=docker-builder .' on the "master" branch of of linz-software-repository
Run docker run --env=DRY_RUN=1 --env=GITHUB_REPOSITORY=linz/postgresql-tableversion --env=RUNNER_WORKSPACE="$(dirname "$PWD")" --volume=/var/run/docker.sock:/var/run/docker.sock docker-builder bionic jq "$PWD" on the postgresql-tableversion "release-1.10" branch
Run docker run --rm --volume="${PWD}/build-area:/packages" tester ./test/ci/package-upgrade.bash 10 to see the error.
Running the Docker container interactively (docker run -it --rm --volume="${PWD}/build-area:/packages" tester bash the extension seems to be installed in the DB after the test fails:
root#b72cee4cd600:/src# su '--command=psql --command="\dx"' postgres
List of installed extensions
Name | Version | Schema | Description
---------------+---------+---------------+---------------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
table_version | 1.10.3 | table_version | PostgreSQL table versioning extension
(2 rows)

pg_repack version mismatch after maintenance on cloud sql (GCP)

I have a cloud-sql postgres11 instance on GCP and use pg_repack cron for cleaning my database. I've noticed that since last maintenance occurred (7th of March 21) I cannot perform a repack.
When tried to manually run a repack I encountered this error message:
ERROR: pg_repack failed with error: program 'pg_repack 1.4.4' does not match database library 'pg_repack 1.4.6'
Did the following checks:
what is the version of pg_repack loaded:
List of installed extensions
Name | Version | Schema | Description
--------------------+---------+------------+--------------------------------------------------------------
pg_repack | 1.4.4 | public | Reorganize tables in PostgreSQL databases with minimal locks
pg_stat_statements | 1.6 | public | track execution statistics of all SQL statements executed
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(3 rows)
what is the available version of pg_repack:
name | version | installed | superuser | relocatable | schema | requires | comment
-----------+---------+-----------+-----------+-------------+--------+----------+--------------------------------------------------------------
pg_repack | 1.4.4 | t | t | f | | | Reorganize tables in PostgreSQL databases with minimal locks
(1 row)
I upgraded pg_repack to version 1.4.6 and it did not help, I also tried to drop and create the extension, or restart the sql-instance with no luck. :-(
I wonder if someone had encouctered this issue. If so, is there any solution?
I got this working on Debian 10 with a very jank workaround. Basically I built a copy of 1.4.6 with the version checks commented out, and successfully ran it with the -k flag:
sudo apt install build-essential postgresql-server-dev-13 libssl-dev zlib1g-dev libreadline-dev
git clone https://github.com/yunyu/pg_repack.git # My fork with the version checks commented out
cd pg_repack
make && sudo make install
./bin/pg_repack <flags>
It seemed to work and I haven't run into any issues. Obviously run this on a VM that can access the Postgres instance, since you need shell access to even execute pg_repack.
Upgrade the extension:
ALTER EXTENSION pg_repack UPDATE;

Installing pg_profile for postgreSql

I am trying to use the extension pg_profile in order to get awr-like reports in postgreSql.
In githab README file it says:
https://github.com/zubkov-andrei/pg_profile
# cp pg_profile* `pg_config --sharedir`/extension
and then:
postgres=# CREATE EXTENSION pg_profile;
But this fails with:
ERROR: could not open extension control file "/usr/share/postgresql/11/extension/pg_profile.control": No such file or directory
and indeed I can only find pg_profile.control.tpl in under this directory (and in the zip file I downloaded from Github).
IF I try to follow the tutorial instructions saying:
https://dbtut.com/index.php/2019/03/29/postgresql-awr/
After downloading the file to the server, go the directory you
downloaded and follow the steps below. We’re running the Make command.
make install
Then I get this error:
# make install
Makefile:16: ../../src/Makefile.global: No such file or directory
Makefile:17: /contrib/contrib-global.mk: No such file or directory
make: *** No rule to make target '/contrib/contrib-global.mk'. Stop.
Any idea how to solve these?
I was able to run CREATE EXTENSION in PG 12.3 database but to do that:
I have removed the line PG_CONFIG = /usr/local/pgsql/bin/pg_config in Makefile:
I have run as root:
$ make USE_PGXS=y install
/usr/bin/mkdir -p '/usr/pgsql-12/share/extension'
/usr/bin/mkdir -p '/usr/pgsql-12/share/extension'
/usr/bin/install -c -m 644 .//pg_profile.control '/usr/pgsql-12/share/extension/'
/usr/bin/install -c -m 644 pg_profile--0.1.1.sql pg_profile.control '/usr/pgsql-12/share/extension/'
And after that I could run without error:
postgres=# CREATE EXTENSION dblink;
postgres=# CREATE EXTENSION pg_stat_statements;
postgres=# CREATE EXTENSION pg_profile;
postgres=# \dx
List of installed extensions
Name | Version | Schema | Description
--------------------+---------+------------+--------------------------------------------------------------
dblink | 1.2 | public | connect to other PostgreSQL databases from within a database
pg_profile | 0.1.1 | public | PostgreSQL load profile repository and report builder
pg_stat_statements | 1.7 | public | track execution statistics of all SQL statements executed
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
postgres_fdw | 1.0 | public | foreign-data wrapper for remote PostgreSQL servers
(5 rows)

Upgrade Postgres Extension / Install Specific Version

1) How do you upgrade a postgres extension?
2) How do you install a specific extension version?
In production the version of hstore is out of date.
=> select * from pg_available_extensions where name ='hstore';
name | default_version | installed_version | comment
--------+-----------------+-------------------+--------------------------------------------------
hstore | 1.3 | 1.1 | data type for storing sets of (key, value) pairs
All the other environments hstore is already at 1.3 so I don't have a way to test if create extension hstore; is all I need.
I'd like to test the upgrade first and ran Postgres 9.4.4 through Docker
docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres:9.4.4
docker run -it --rm --link some-postgres:postgres postgres:9.4.4 psql -h postgres -U postgres
but hstore 1.3 was the default version
name | default_version | installed_version | comment
--------+-----------------+-------------------+--------------------------------------------------
hstore | 1.3 | 1.3 | data type for storing sets of (key, value) pairs
To upgrade a postgres extension
install the latest version
ALTER EXTENSION hstore UPDATE;
install a specific version
list available extensions
SELECT * FROM pg_available_extension_versions WHERE name ='hstore';
install the specific version
ALTER EXTENSION hstore UPDATE TO '1.3';
Install a specific version older than the default version
Download the version from the postgres repo to the pg_config extension directory.
wget --directory-prefix /usr/share/postgresql/9.4/extension/ \ https://raw.githubusercontent.com/postgres/postgres/REL9_2_STABLE/contrib/hstore/hstore--1.1.sql
Check available versions
SELECT * FROM pg_available_extension_versions WHERE name ='hstore';
Install specific version
CREATE EXTENSION hstore WITH VERSION '1.1';

GeoDjango: editing the standard PostGIS template to include OSGB36

I've just installed GeoDjango (yay) and now I'm trying to follow these instructions to set up an existing GeoDjango project, which needs OSGB36:
After you've installed and got a PostGIS template, log
in to it and update the proj4text column of SRID 27700 to include
+datum=OSGB36, and update SRID 29902 to have +datum=ire65.
However. If I connect to the postgis_template created as part of the GeoDjango install, it doesn't appear to have any rows or columns at all:
domesday=# \c template_postgis
psql (8.4.4)
You are now connected to database "template_postgis".
template_postgis=# \d
No relations found.
How do I make the edits necessary to update SRID 27700 and SRID 29902 as described here? Have I created template_postgis wrong? I didn't see any errors during install.
What you should see is:
template_postgis=# \d
List of relations
Schema | Name | Type | Owner
--------+------------------+-------+----------
public | geometry_columns | table | postgres
public | spatial_ref_sys | table | postgres
(2 rows)
Since you're not, you probably had a problem running:
$ psql -d template_postgis -f $POSTGIS_SQL_PATH/postgis.sql
On my (Ubuntu+PG8.3) system, that file is actually called lwpostgis.sql. I had similar issues when installing the first time.