Skip to content

Instantly share code, notes, and snippets.

@jobliz
Created June 22, 2018 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jobliz/439da26f67fe48494ffdffd86b275834 to your computer and use it in GitHub Desktop.
Save jobliz/439da26f67fe48494ffdffd86b275834 to your computer and use it in GitHub Desktop.
PostgreSQL database configuration with ltree extension

PostgreSQL database configuration with ltree extension

  1. Install PostgreSQL database (apt install postgresql postgresql-contrib under Ubuntu)
  2. Log in to the postgres account: sudo --login --user postgres
  3. Start the PostgreSQL interactive terminal: psql
  4. Create the database: postgres=# CREATE DATABASE my_database;
  5. Create a user: postgres=# CREATE USER my_user WITH PASSWORD 'my_password';
  6. Grant the user access to the database. postgres=# GRANT ALL PRIVILEGES ON DATABASE my_database to my_user;
  7. Switch to the database: \connect my_database;
  8. Enable ltree extension on the database: create extension ltree;
  9. Exit psql: \q
@jobliz
Copy link
Author

jobliz commented Jul 18, 2018

For Django to create test databases you also need to do ALTER USER my_user CREATEDB; inside psql.

@jobliz
Copy link
Author

jobliz commented Oct 1, 2018

If you want to run DROP SCHEMA public and/or CREATE SCHEMA public; you must set the created user as owner of the schema with:

ALTER SCHEMA public OWNER TO my_user;`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment