I know how to read PostgreSQL tables in remote server with psycopg2, sqlalchemy, dask but I am not satisfied with processing time to read the tables and started researching faster alternatives and I found asyncpg as 7x more faster than all but documentation for asyncpg is very poor compared to above referred libraries which are plenty of examples over there.
My question is: how to read PostgreSQL tables efficiently?
I have tried as below:
import asyncio
import asyncpg
import pandas as pd
from sshtunnel import SSHTunnelForwarder #Allow connection with SSH like PuttY connection
from sshtunnel import SSHTunnelForwarder, create_logger #Allow to follow the processes running
SSHTunnelForwarder(('IP_detail', Port_number),
ssh_private_key=r'path_to_the_ssh_key_in_my_computer',
ssh_username="username",
#ssh_password="password",
remote_bind_address=('localhost', port_number),
local_bind_address=('localhost', port_number),
logger=create_logger(loglevel=1) #Makes processes being ran displayed
)
conn = await asyncpg.connect(user='username', password='password',
database='database_name', host='127.0.0.1', port='port')
values = await conn.fetch('''SELECT * FROM table_name''')
values=pd.DataFrame(values)
values
With above code I get the PostgreSQL table all rows values for every columns but doesn't show column names and it shows columns numbering instead of their proper names. How to correct this?