is your Alliance username. You cannot create a database yourself. If you need more than one database, please send a request to [[Technical support]].
You do not need to supply a password to access your PostgreSQL account. For security reasons your Alliance password must NEVER be required or used in a script. This also means that one user cannot access another user's database directly.
Run the "psql" client to connect to the PostgreSQL server. An older version of the client may be available without loading a [[Utiliser des modules/en|module]], but it will not give you access to the latest features of PostgreSQL. We recommend loading the following module to use a more recent version of the client:
[name@server ~]$ module load postgresql
[name@server ~]$ psql --version
=== Work with your PostgreSQL database ===
Suppose you have account "david" and have been assigned a database called "david_db". Here is an example of how to use it from the Cedar head node:
{{Command|psql -h cedar-pgsql-vm -d david_db
david_db{{=}}> -- List names of tables in your database
david_db{{=}}> \dt
david_db{{=}}> ... Issue SQL commands. See below for more information.
david_db{{=}}> -- Quit
david_db{{=}}> \q
}}
Resources for using PostgreSQL:
* [https://www.postgresql.org/docs/current/static/tutorial.html PostgreSQL tutorials]
* [https://www.postgresql.org/docs/ PostgreSQL manuals]
* [https://www.postgresql.org/docs/release/ PostgreSQL release notes]
=== Share your PostgreSQL data ===
You can share your data in your PostgreSQL database with others. This is how:
* The person with whom you want to share access must have a Postgres account on the system. They should apply for one as described above.
* You will have to give the person connect
access to your database.
* For each table or view to be shared, you give the person one or more of select, update, insert
, and delete
access to it.
* You can also revoke access to a table, view, or database.
Here is an example of user 'david' sharing a table with user 'kim':
{{Command|psql -h cedar-pgsql-vm -d david_db
david_db{{=}}> -- Give kim connect access to the database
david_db{{=}}> grant connect on database david_db to kim;
david_db{{=}}> -- Give kim select-only access to a table called mytable
david_db{{=}}> grant select on mytable to kim;
david_db{{=}}> -- Quit
david_db{{=}}> \q
}}
Here is an example of user 'kim' accessing the shared table:
{{Command|psql -h cedar-pgsql-vm -d kim_db
kim_db{{=}}> -- Connect to the database containing the table to be accessed
kim_db{{=}}> \c david_db
david_db{{=}}> -- Display the rows in the shared table
david_db{{=}}> select * from mytable;
david_db{{=}}> -- Quit
david_db{{=}}> \q
}}
Here is an example of user 'david' revoking access to 'kim':
{{Command|psql -h cedar-pgsql-vm -d david_db
david_db{{=}}> -- Revoke kim's select-only access to a table called mytable
david_db{{=}}> revoke select on mytable from kim;
david_db{{=}}> -- Revoke kim's connect access to the database
david_db{{=}}> revoke connect on database david_db from kim;
david_db{{=}}> -- Quit
david_db{{=}}> \q
}}
== Graham MySQL server ==
The steps for obtaining and using an account on the Graham MySQL server are similar to [[#Cedar_MySQL_server|those described above for Cedar]].
== Cloud-based database servers ==
=== Database as a Service (DBaaS) ===
If a VM is not sufficient to run a database load, a managed database can be used instead, the current offering includes MySQL/MariaDB and Postgres on a physical system.
The database systems as well as all databases are being backed up once a day. The backups are archived for 3 months.
To request access, please contact [[Technical support]].
'''Please provide in your request the client network or IP address you will access the database from.'''
{| class="wikitable"
|-
! Type !! Hostname !! TCP port
|-
| mysql || dbaas101.arbutus.cloud.computecanada.ca || 3306
|-
| pgsql || dbaas101.arbutus.cloud.computecanada.ca || 5432
|}
The CA certificate which is used to sign the host certificate for the service, is available for download [https://docs.computecanada.ca/mediawiki/images/5/58/Dbaas-ca.pem.zip here].
=== PostgreSQL database ===
Your instance will use an ssl connection to connect to the DBaaS host.
The example below connects to the DBaaS host, as '''''user01''''' and uses the database '''''dbinstance''''' via an ssl connection.
psql --set "sslmode=require" -h dbaas101.arbutus.cloud.computecanada.ca -U user01 -d dbinstance
Password for user user01:
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
dbinstance=> \l dbinstance
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
------------+--------+----------+-------------+-------------+-------------------
dbinstance | user01 | UTF8 | en_US.UTF-8 | en_US.UTF-8 | user01=CTc/user01
(1 row)
The ssl connection is enforced and plain text connections fail.
=== MariaDB/MySQL database ===
Your instance will use an ssl connection to connect to the DBaaS host.
The example below connects to the DBaaS host, as '''''user01''''' and uses the database '''''dbinstance''''' via an ssl connection.
mysql --ssl -h dbaas101.arbutus.cloud.computecanada.ca -u user01 -p dbinstance
Enter password:
MariaDB [dbinstance]> show databases;
+--------------------+
| Database |
+--------------------+
| dbinstance |
| information_schema |
+--------------------+
2 rows in set (0.001 sec)
If you try to use a plain text connection, your authentication will fail.
mysql -h dbaas101.arbutus.cloud.computecanada.ca -u user01 -p dbinstance
Enter password:
ERROR 1045 (28000): Access denied for user 'user01'@'client.arbutus' (using password: YES)