Enable extension in Postgresql for database user without superuser permissions

Sometime an application may need access to specific Postgres functions, but for security reason, the application's database user may not have superuser privileges to enable extensions in Postgres (which is a good thing).

Here's how you can enable the necessary extension on a specific database using the superuser account. After the extensions are enabled on a database, the database user will be able to use it.

  1. Login to Postgres PSQL prompt as superuser
    sudo -u postgres psql


  2. Connect to the database which needs the extensions
    \c mydatabase (use \l to list databases)


  3. Enable the extension on the database
    CREATE EXTENSION "uuid-ossp";


  4. Quit PSQL
    \q


Comments