How to load Chinook database in PostgreSQL? How to load Chinook database in PostgreSQL? postgresql postgresql

How to load Chinook database in PostgreSQL?


The short answer to this is to use John Atten's version which is available here on his github. The rest of this is a short guide on how to run this.

The following assumes you have already installed and started an instance of PostgreSQL

Download the SQL Script

The official versions of the Chinook scripts can be found here. At time of writing, however, the standards for table and column names currently follow other standards. John Atten modified the official version to follow PostgreSQL standards, such as using the serial type, and it's available here. This is the version I used for this process.

Create the Database

Run a command to create a DB in which to store the chinook database. This one is named chinook for simplicity.

$ createdb chinook$

Run the Downloaded File Using psql

psql can be used to run the creation code on the newly created database. If you are operating on a remote database, replace chinook with a connection string.

The -1 runs the entire file as a transaction, ensuring that you won't get a partially completed database on your server.

&>errorlog.txt will store the resulting output to the file errorlog.txt.

$ psql chinook -1 -f ~/Path/To/Download/chinook_pg_serial_pk_proper_naming.sql &>errorlog.txt$

Test the DB to Ensure the Data Loaded

You should now check to see if the data loaded properly. You could use PGAdmin or Postico, but it can easily be checked from the command line using psql's \d command. Here is an example:

Once again, if connecting remotely, replace chinook with a connection string

$ psql chinookpsql (10.1)Type "help" for help.chinook=# \d                   List of relations Schema |              Name              |   Type   |  Owner--------+--------------------------------+----------+---------- public | actor                          | table    | pmitdev1 public | actor_actor_id_seq             | sequence | pmitdev1 public | album                          | table    | pmitdev1 public | album_album_id_seq             | sequence | pmitdev1 public | artist                         | table    | pmitdev1 public | artist_artist_id_seq           | sequence | pmitdev1 public | category                       | table    | pmitdev1 public | category_category_id_seq       | sequence | pmitdev1 public | customer                       | table    | pmitdev1 public | customer_customer_id_seq       | sequence | pmitdev1 public | employee                       | table    | pmitdev1 public | employee_employee_id_seq       | sequence | pmitdev1 public | film                           | table    | pmitdev1 public | film_actor                     | table    | pmitdev1 public | film_category                  | table    | pmitdev1 public | film_film_id_seq               | sequence | pmitdev1 public | genre                          | table    | pmitdev1 public | genre_genre_id_seq             | sequence | pmitdev1 public | invoice                        | table    | pmitdev1 public | invoice_invoice_id_seq         | sequence | pmitdev1 public | invoice_line                   | table    | pmitdev1 public | invoiceline_invoiceline_id_seq | sequence | pmitdev1 public | media_type                     | table    | pmitdev1 public | mediatype_mediatype_id_seq     | sequence | pmitdev1 public | playlist                       | table    | pmitdev1 public | playlist_playlist_id_seq       | sequence | pmitdev1 public | playlist_track                 | table    | pmitdev1...