To export data from the data warehouse (DW), you need to log in to the 5GIR DW database with either Bash code on Linux (and Mac? not tested), CMD code on Windows, or Python code on any operating system.
Open the bash terminal on Linux and MACs.
dbname=database_name
host=host_domain
port=host_port
username=user_name
psql --dbname="$dbname" --host="$host" --port="$port" --username="$username" --password
Open the Command Prompt on Windows.
psql.exe has been added to the Path environment variable, then you
can skip this step and move to step 3. Otherwise, you need to locate the directory and add it to PATH every time
you open a new Git bash window before running the command psql. An example of a Postgres directory is
C:\Program Files\PostgreSQL\14\bin which must contain the file “psql.exe”. If this is the case for you, you can add
it to PATH with:
set "PATH=%PATH%;C:\Program Files\PostgreSQL\14\bin;"
If the directory is different in your case, adjust the directory accordingly.
Define the database name, host name, server port and username with the code below by replacing database_name, host_domain, host_port and user_name with the database name, host name, server port and username, respectively.
set "dbname=database_name"
set "host=host_domain"
set "port=host_port"
set "username=user_name"
psql --dbname=%dbname% --host=%host% --port=%port% --username=%username% --password
credentials.json. (If you do not know what a JSON file is and how to
create it, it is a text file. So, create a text file with name credentials.json.) Add to the new file with the
following content, and replace {
"user": <username>,
"pass": <password>,
"IP": <postgresql_server_domain>,
"port": <postgresql_server_port>
}
main.py. (If you don’t know how, just create a text file and name it main.py). Next, add
the following Python code in the new file and replace from data_warehouse_client import data_warehouse
dw = data_warehouse.DataWarehouse('credentials.json', '<database>')
conda activate fgir
python main.py
If you have successfully connected to the database, you should see a message saying:
Init successful! Running queries.