Is there a way to install PL/Python after the database has been compiled without "--with-python" parameter? - postgresql

Ubuntu 14.04.3, PostgreSQL 9.6
Maybe I can get the plpythonu source code from the PostgreSQL 9.6 source code or somewhere else, put it into the /contrib directory, make it and CREATE EXTENSION after that!? Or something like that.
Don't want to think that PostgreSQL reinstall is my only way.

you can simply run
python 2
sudo apt-get install postgresql-contrib postgresql-plpython-9.6
python 3
sudo apt-get install postgresql-contrib postgresql-plpython3-9.6
Then check the extension is installed
SELECT * FROM pg_available_extensions WHERE name like '%plpython%';
To apply the extension to the database, use
for python 2
CREATE EXTENSION plpython2u;
for python 3
CREATE EXTENSION plpython3u;

Related

Postgres 12 Extensions Not Installed on RHEL 7

Looking to install the pgstattuple extension on my Postgres 12 DB on RHEL 7 to see index fragmentation. Currently I only have one extension installed and that's the plpgsql extension.
Executing 'CREATE EXTENSION pgstattuple' results in the following error:
SQL Error [58P01]: ERROR: could not open extension control file "/usr/pgsql-12/share/extension/pgstattuple.control": No such file or directory
And I verified that the pgstattuple.control is not located in the /usr/pgsql-12/share/extension folder.
Searching around the net, seemed to indicate that the postgresql-contrib needed to be installed to get the pgstattuple extension. So I did the following command:
$ sudo yum install postgresql-contrib
Unfortunately the yum install postgresql-contrib resulted in the pgstattuple and other extensions being installed into the /usr/pgsql-9.6/share/extension
folder, and not in the /usr/pgsql-12/share/extension folder where I want them.
For giggles, I tried copying all the pgstattuple* files in /usr/pgsql-9.6/share/extension to /usr/pgsql-12/share/extension folder, and then tried calling CREATE extension pgstattuple, but that didn't work with another error.
Questions are:
Should I expect sudo yum install postgresql-contrib to actually install the pgstattuple extension for Postgres 12?? Or is there some other package name for Postgres 12?
Could this be some problem with my Red Hat Repository configuration?
In general what's the command to install the pgstattuple extension for Postgres 12 so that the pgstattuple files will end up in /usr/pgsql-12/share/extension folder??
Really appreciate any suggestions you have.
Thank you.

How to install uuid-ossp postgresql extension in arch Linux

I need to install uuid-ossp postgresql extension on arch linux. I have postgresql-9.5. On ubuntu its easy to do via sudo apt-get install postgresql-contrib but how to do this in arch Linux?
The default postgresql package doesn't provide ossp-uuid-feature. You have to enable it via ./configure before compiling. So you have two ways to get this feature:
compile postgresql yourself with --with-ossp-uuid-flag and install it via make install. (I don't recommend this)
Download the postgresql package specifications via the tool asp. You can install it with sudo pacman -Syu asp and then do: asp checkout postgresql. Then you need to modify the PKGBUILD and insert the --with-ossp-uuid-flag inside of the build()-function. Then you can simply build the package and install it with makepkg -si. It is possible that you need additional dependencies. I haven't tested it, but it should work this way.

How to install Postgis to a Keg installation of Postgres#9.6 using Homebrew?

I have installed Postgresql#9.6 and Postgis via Homebrew. However, installing Postgis via Homebrew installs the latest version of Postgresql at 10 as dependency and pinning Postgresql at 9.6.5 blocks the install of Postgis via Homebrew.
Performing 'CREATE EXTENSION postgis;' returns:
ERROR: could not open extension control file "/usr/local/Cellar/postgresql#9.6/9.6.5/share/postgresql#9.6/extension/postgis.control": No such file or directory
I've also tried uninstalling the Postgresql (at 10) and editing the Postgis formula to depend on Postgres#9.6 instead of Postgresql.
This is similar to How to install Postgis to a Keg installation of Postgres#9.5 using Homebrew? but with a later keg formula
I managed to do it after many combinations.
In a nutshell, solution is to install the old version of the original package postgres, switch to it, and install the old version of postgis.
Install postgres
1/ Install the current version of postgres (10.1 as speaking)
brew install postgres
2/ Install the old version of postgres using its old formula. Proper link can be found using github or git log on the Tap repo (/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/).
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/d014fa223f77bee4b4097c5e80faa0954e28182f/Formula/postgresql.rb
This will install the version 9.6.5 (last one before 10.x series).
3/ Switch to it so links are defaulted to postgres 9.6
brew switch postgres 9.6.5
Install postgis
4/ Install old version of postgis (2.3). This is using the same sha version of the Formula so everything is linked correctly (using the current postgis will expect postgresql 10, so it will end up to a version mismatch when initializing extension).
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/d014fa223f77bee4b4097c5e80faa0954e28182f/Formula/postgis.rb
Use them
5/ If required initialise the DB
initdb /usr/local/var/postgres
6/ Create and use your DB
createdb mydb
psql mydb
mydb=# CREATE EXTENSION postgis;
Installing PEX, a package manager for Postgresql allowed me to install Postgis for the keg version of Postgresql#9.6 and use CREATE EXTENSION postgis;
This isn't a Homebrew solution but after a lot of searching, it finally allowed me to use Postgis.
HelloI ran into this same problem of multiple implementation of pgsql versions including legacy ones. So after a bit of research I would like to share my solution.
Problem:
I am working on a macbook pro 2013 with 10.11 el capitan. I am GIS developer and extensive user of homebrew. I didn't pin the postgresql package for compatibility reasons. Thus, the package got updated to postgresql version 10.5 along other packages. This caused me to be unable to use postgresql version 9.4. The cleverest solution would have been to use a brew switch postgresql 9.4.19. Except that when compiling postgis 2.5.0 from osgeo/osgeo4mac it defautls (looks for) the postgresql binary folder to install the symlinked (or not) extensions. Here again another compatibility problem. One could tinker a bit with homebrew files and transfer files manually. That's ill advice...the package manager (homebrew) needs to stay a coherent ecosystem to provide for a stable workspace.
Proposed Solution:
Go here BigSQL and download the dmg of your chosen version
install the software where you want in your filesystem
within the installation folder you'll find a directory named pg9x ; x being the version number (e.g pg95 for postgresql 9.5 and so on...
in this folder you'll find a file named pg9x.env
source this file to your .profile with source /your/path/pg9x/pg9x.env line
in the main installation folder, for instance /your/path/pg9x/, you'll finde a python script called pgc, alias it to your .profile with alias pgc="your/path/pgc"
save your .profile and refresh your environment variable with source .profile on the command prompt
still within the command prompt, type pgc list, you'll get a list of installed packages. You'll see the version of postgesql you've downloaded
to install another version of postgresql, say 9.6, type pgc install pg96
to install postgis for pg95 type pgc install postgis22-pg95
to install postgis for pg96 type pgc install postgis23-pg96
now, after installation you'll need to initialize the downloaded component with pgc init pg96 or pgc init postgis23-pg96 etc...
to check if your daemon is running correctly type pgc status
to start a version daemon of your choice type for example pgc start pg95
to stop a version daemon of your choice type pgc stop pg95
the installation also comes with an LTS release of pgadmin3 that works fine with all versions (not the case of brew version of pgadmin3), this is very convenient
type pgc help for more options
Let the elephant dance^^
Hope this helps.
Spicy.
I faced a similar issue and what worked for me was to follow the instructions at https://github.com/CloverHealth/homebrew-tap, which seem similar in spirit to #Antwan's solution but with a few more clean up steps, also it gets slightly later versions: postgresql 9.6.10 and postgis 2.5.
My steps differed slightly from those at CloverHealth: My brew version no longer supports brew switch postgresql 9.6.10 and I tried first brew link postgresql#9.6.10 and then brew link postgresql#9.6 but both gave
Error: no such keg
Trying brew search postgresql showed a little green checkmark next to the cloverhealth Formulae, so I tried brew link cloverhealth/tap/postgresql and got
Warning: Already linked: /usr/local/Cellar/postgresql/9.6.10
So, ok it was already linked. Other than that my steps were the same as described at the CloverHealth page, and now I'm up and running again.

Postgres and unaccent extension default directory

I need to add an extension called unaccent to my postgres database.
Postgres version PostgreSQL version: 9.3rc1
I have a problem to install the extension.
What i did:
sudo apt-get install postgresql-contrib-9.1
I know it's with 9.1 version, but on my test server i did everyting the same with postgres version 9.4, and everything works.
When i run a script on my production server
CREATE EXTENSION unaccent schema pg_catalog;
it throws me an error :
could not open extension control file "/usr/local/pgsql/share/extension/unaccent.control": Directory or file doesn't exist
What is the problem in this case? Extension has been installed into "wrong" (i guess) directory /usr/share/postgresql/9.1/extension instead of usr/local/pgsql/share/extension
Is there any chance to make postgres look into other directory than default for extensions?
Don't use PostgreSQL 9.3rc1. Just don't. That's not a production version.
You have to install the contrib modules from the same source and in the same version as PostgreSQL core. Everything else won't work.
So this is what you should do:
Upgrade PostgreSQL to something more recent, at leat 9.3.14.
Install the contrib modules from the same provider in the same version.

How to use pg_trgm after postgresql installation from source

After succesfully installing postgresql 9.2.2 from source (on OpenSUSE 11.4, which does not have this version in the repositories), I am trying to restore a database that makes use of the pg_trgm extension. This results in errors because pg_trgm is not found.
From this StackOverflow question: Similarity function in Postgres with pg_trgm, I gather that pg_trgm should be in /usr/share/postgresql//contrib, but there is no contrib folder anywhere in my /usr tree.
Also, I cannot seem to find a clear explanation of how the postgres extension mechanism works, or how to manually install an extension.
There is a contrib folder in the postgresql source tree, but I am not sure how to use this. Should I manually copy this somewhere to /usr tree? Can anyone point me to (or give) an explanation of how to install an extension like pg_trgm in postgresql?
Assuming you have configured postgresql with ./configure, it has used the default prefix /usr/local/pgsql, so that everything gets installed below that directory.
The answer you link to relates to Debian, which uses a different layout that conforms to the Debian policy, but in your case /usr/share... is irrelevant. Anyway it's not really necessary to know that in order to install stuff from contrib, since there is no need to copy anything manually.
To install the pg_trgm extension from source, there are two steps:
1) build and install it from your postgresql source tree:
$ cd /path/to/src/postgresql-9.2.2/contrib/pg_trgm
$ make
$ sudo make install # or su -c 'make install' if you don't use sudo
2) activate it with psql in your database:
$ sudo -u postgres psql -d database -c "create extension pg_trgm;"
To have it activated by default on any database created in the future, apply this command to the template1 database.
I've use Postgresql in the Centos 7 and the package with the pg_trgm allowed to install:
$yum install postgresql-contrib