Difference between revisions of "PostgreSQL"

From Briki
Jump to: navigation, search
(PostgresSQL)
Line 1: Line 1:
== PostgresSQL ==
+
== Creating a DB ==
 
 
=== Creating a DB ===
 
 
   sudo -u postgres createdb <dbname>
 
   sudo -u postgres createdb <dbname>
  
=== Creating a role ===
+
== Creating a role ==
 
Note that in postgres all access is managed by "roles", there is no concept of users or groups (though for historical purposes users and roles can be thought of as largely interchangeable).
 
Note that in postgres all access is managed by "roles", there is no concept of users or groups (though for historical purposes users and roles can be thought of as largely interchangeable).
  
Line 13: Line 11:
 
   sudo -u postgres createuser <username> -P
 
   sudo -u postgres createuser <username> -P
  
=== Authentication ===
+
== Authentication ==
==== Local Users ====
+
=== Local Users ===
 
By default (defined in `/etc/postgresql/11/main/pg_hba.conf`), local users can authenticate without needing a password into a role with the same name as their username.
 
By default (defined in `/etc/postgresql/11/main/pg_hba.conf`), local users can authenticate without needing a password into a role with the same name as their username.
  
==== Remote Users ====
+
=== Remote Users ===
 
Remote users (including those connecting from other docker containers) can only connect as roles with passwords defined.
 
Remote users (including those connecting from other docker containers) can only connect as roles with passwords defined.
  
=== Starting an interactive session ===
+
== Starting an interactive session ==
 
   psql <dbname>
 
   psql <dbname>

Revision as of 11:35, 7 February 2020

Creating a DB

 sudo -u postgres createdb <dbname>

Creating a role

Note that in postgres all access is managed by "roles", there is no concept of users or groups (though for historical purposes users and roles can be thought of as largely interchangeable).

Without a password:

 sudo -u postgres createuser <username>

With a password:

 sudo -u postgres createuser <username> -P

Authentication

Local Users

By default (defined in `/etc/postgresql/11/main/pg_hba.conf`), local users can authenticate without needing a password into a role with the same name as their username.

Remote Users

Remote users (including those connecting from other docker containers) can only connect as roles with passwords defined.

Starting an interactive session

 psql <dbname>