-
Notifications
You must be signed in to change notification settings - Fork 6
Postgres Setup Guide
Shirley Cohen edited this page Jan 29, 2021
·
2 revisions
Follow this guide to set up your Postgres environment for this class.
- Go to the GCP console.
- From the nav menu, click on SQL and then click on Create Instance.
- From the create an instance screen, click on Choose PostgreSQL.
- Name your Postgres instance. For example, pg.
- Set a root password. Make sure you remember it!
- For region, choose us-central1 (Iowa) and Zone, Any.
- For database version, select PostgreSQL 9.6.
- Click on Configuration options
- Expand the Connectivity option and uncheck Public IP and check Private IP.
- Expand the Backups, recovery and high availability option and uncheck Enable point-in-time recovery.
- Don't make any other changes.
- Click the Create button to create your Postgres instance.
- While your instance is coming up, go to AI Platform Notebooks and start your Jupyter notebook instance.
- Open a terminal window and run
sudo apt-get install postgresql-clientto install the Postgres client libraries. - Create a
.bash_profilefile with the following lines:
export PGDATABASE=postgres
export PGHOST={private IP}
export PGPORT=5432
export PGUSER=postgres
export PGPASSWORD={password}
- Run
source .bash_profileto set the environment variables or just open a new terminal window. - Run
psqlto bring up the postgres client. If you get the following output, your Postgres setup is complete.
(base) jupyter@python-notebook:~$ psql
psql (9.6.17, server 9.6.18)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES128-GCM-SHA256, bits: 128, compression: off)
Type "help" for help.
postgres=>
- Once you have tested connectivity, stop your Postgres instance and Jupyter instance. If you forget to stop those resources, you will quickly run out of GCP credits!