Postgresql – How to install pgcrypto

linuxpostgresql

While trying to answer Create integer id columns from existing string columns (integer coding?) it turned out that I needed my own version of postgres to play with. I already had a decent postgres version installed:

stack=# select version();
                                                version                         

--------------------------------------------------------------------------------
------------------------
 PostgreSQL 11.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 9.1.1 20190503 (R
ed Hat 9.1.1-1), 64-bit

but it did not have the pgcrypto module:

stack=# CREATE EXTENSION pgcrypto;
ERROR:  could not open extension control file "/usr/pgsql-11/share/extension/pgcrypto.control": No such file or directory

so I installed:

sudo dnf install postgresql-contrib 

but I still get the same error. If I look in:

]$ ls /usr/pgsql-11/share/extension/
plpgsql--1.0.sql  plpgsql.control  plpgsql--unpackaged--1.0.sql

Is there any other package I need to install, or am I missing something else?

UPDATE:

rpm -qa postgresql\* 
postgresql-contrib-11.3-1.fc30.x86_64 
postgresql11-11.4-1PGDG.f30.x86_64 
postgresql-11.3-1.fc30.x86_64 
postgresql11-server-11.4-1PGDG.f30.x86_64 
postgresql11-libs-11.4-1PGDG.f30.x86_64 

I get an error for dnf install postgresql11-contrib:

[…]
Failed to synchronize cache for repo 'fedora-modular'
Error: Failed to synchronize cache for repo 'fedora-modular'

pdgd seems to be the latest availible:

rpm -qa | grep pgdg-fedora
pgdg-fedora-repo-42.0-4.noarch

UPDATE2:

Apparently something where temporarily down, it now worked to:

sudo dnf install postgresql11-contrib
[...]
Downloading Packages:
postgresql11-contrib-11.4-1PGDG.f30.x86_64.rpm  285 kB/s | 602 kB     00:02    

rpm -qa postgresql\*
postgresql-contrib-11.3-1.fc30.x86_64
postgresql11-11.4-1PGDG.f30.x86_64
postgresql11-contrib-11.4-1PGDG.f30.x86_64
postgresql-11.3-1.fc30.x86_64
postgresql11-server-11.4-1PGDG.f30.x86_64
postgresql11-libs-11.4-1PGDG.f30.x86_64

stack=# CREATE EXTENSION pgcrypto;
CREATE EXTENSION

Best Answer

contrib is correct, but you must have installed it for a different PostgreSQL than the one you are using.

Find out which packages are installed:

rpm -qa postgresql\*

Odds are that you need to run

dnf install postgresql11-contrib