-
Notifications
You must be signed in to change notification settings - Fork 8
Postgres Setup Guide
shaniyur edited this page Feb 2, 2022
·
4 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).
- For Zone Availability, click Single and keep the primary zone as Any.
- For database version, select PostgreSQL 13.
- 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 Vertex AI and start up your Jupyter notebook instance.
- In your notebook, open a terminal window and run the following commands:
sudo apt update
sudo apt -y install gnupg2
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" |sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt update
sudo apt -y install postgresql-client-13
- Create a
.bash_profile
file on Jupyter Notebook (similar to creating the cnf file) with the following lines:
export PGDATABASE=postgres
export PGHOST={private IP}
export PGPORT=5432
export PGUSER=postgres
export PGPASSWORD={password}
- Run
source .bash_profile
to set the environment variables or just open a new terminal window. - Run
psql
to bring up the postgres client. If your output looks like this, your Postgres setup is complete.
jupyter@python:~$ psql
psql (13.5 (Debian 13.5-1.pgdg100+1), server 13.4)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.
postgres=>
- Once you have tested connectivity, please remember to stop your Postgres instance and your Jupyter instance. If you leave those resources running, you will quickly run out of credits!