Postgres (SQL) - SELECT data in a table on OpenShift
by
Jeremy Canfield |
Updated: June 05 2023
| Postgres (SQL) articles
Let's say you have Postgres running in a pod on OpenShift. If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command. The oc get pods command can be used to list the pods.
~]# oc get pods
NAME READY STATUS RESTARTS AGE
postgres-9mzm2 1/1 Running 0 8d
The oc exec and psql --list commands be used to list the Postgress databases.
~]# oc exec pod/postgres-9mzm2 -- psql --username postgres_user --list
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+------------+------------+-----------------------
db001 | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
db002 | john.doe | UTF8 | en_US.utf8 | en_US.utf8 |
List the tables in a database.
~]# psql --username postgres_user --dbname my_database --command database_name "select * from pg_catalog.pg_tables"
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity
--------------------+-----------------------+------------+------------+------------+----------+-------------+-------------
public | table001 | john.doe | | t | f | t | f
public | table002 | john.doe | | t | f | f | f
public | table003 | john.doe | | t | f | t | f
And then you should be able to select the data from the columns in the table.
oc exec pod/postgres13-587bf9588f-xfcn2 -- psql --username postgres_user --dbname my_database --command "select * from your_table"
Did you find this article helpful?
If so, consider buying me a coffee over at