Skip to content

Instantly share code, notes, and snippets.

@jackwotherspoon
Created April 25, 2024 19:19
Show Gist options
  • Save jackwotherspoon/8a9af3ac1e60e493d32364b3931c6feb to your computer and use it in GitHub Desktop.
Save jackwotherspoon/8a9af3ac1e60e493d32364b3931c6feb to your computer and use it in GitHub Desktop.
AlloyDB Private IP Connection test
from datetime import datetime
import os
import asyncpg
async def main() -> None:
"""Basic test to get time from database using native asyncpg connection."""
async with asyncpg.create_pool(
user="postgres",
password="my-password",
host="10.59.16.2", # your AlloyDB instance IP address
port=5432,
database="postgres", # your database name
ssl="require",
) as pool:
# acquire connection from native asyncpg connection pool
async with pool.acquire() as conn:
time = await conn.fetchrow("SELECT NOW()")
print("Current time is ", time[0])
# run main
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment