AWS RDS 代理错误 (postgres) - RDS 代理目前不支持命令行选项
AWS RDS Proxy error (postgres) - RDS Proxy currently doesn’t support command-line options
我尝试读取或写入 from/to 以 postgres RDS 作为端点的 AWS RDS 代理。
该操作适用于 psql,但在 Python.
中使用 pg8000 或 psycopg2 作为客户端库的同一客户端失败
如果我直接将 RDS 用作端点(没有 RDS 代理),则该操作适用于 pg8000 和 psycopg2。
sqlaclchemy/psycopg2 错误信息:
Feature not supported: RDS Proxy currently doesn’t support command-line options.
我使用的代码的最小版本:
from sqlalchemy import create_engine
import os
from dotenv import load_dotenv
load_dotenv()
login_string = os.environ['login_string_proxy']
engine = create_engine(login_string, client_encoding="utf8", echo=True, connect_args={'options': '-csearch_path={}'.format("testing")})
engine.execute(f"INSERT INTO testing.mytable (product) VALUES ('123')")
pg8000: 它停止/等待的地方在 core.py:
def sock_read(b):
try:
return self._sock.read(b)
except OSError as e:
raise InterfaceError("network error on read") from e
我使用的代码的最小版本:
import pg8000
import os
from dotenv import load_dotenv
load_dotenv()
db_connection = pg8000.connect(database=os.environ['database'], host=os.environ['host'], port=os.environ['port'], user=os.environ['user'], password=os.environ['password'])
db_connection.run(f"INSERT INTO mytable (data) VALUES ('data')")
db_connection.commit()
db_connection.close()
对于我提到的所有示例,RDS 代理 中的日志看起来总是正常的 - 例如:
A new client connected from ...:60614.
Received Startup Message: [username="", database="", protocolMajorVersion=3, protocolMinorVersion=0, sslEnabled=false]
Proxy authentication with PostgreSQL native password authentication succeeded for user "" with TLS off.
A TCP connection was established from the proxy at ...:42795 to the database at ...:5432.
The new database connection successfully authenticated with TLS off.
我通过 RDS 和 RDS 代理上的安全组打开了所有端口,并在 VPC 内使用了 EC2。
我尝试打开和关闭自动提交。
所指的“命令行选项”是 -csearch_path={}
。
删除它,然后在建立连接后执行 set search_path = whatever
作为您的第一个查询。
这是一个已知问题,pg8000 无法连接到 AWS RDS 代理 (postgres)。我做了一个 PR https://github.com/tlocke/pg8000/pull/72 let see if Tony Locke (the father of pg8000) approves the change. ( if not you have to change the lines of the core.py https://github.com/tlocke/pg8000/pull/72/files )
self._write(FLUSH_MSG)
if (code != PASSWORD):
self._write(FLUSH_MSG)
我尝试读取或写入 from/to 以 postgres RDS 作为端点的 AWS RDS 代理。 该操作适用于 psql,但在 Python.
中使用 pg8000 或 psycopg2 作为客户端库的同一客户端失败如果我直接将 RDS 用作端点(没有 RDS 代理),则该操作适用于 pg8000 和 psycopg2。
sqlaclchemy/psycopg2 错误信息:
Feature not supported: RDS Proxy currently doesn’t support command-line options.
我使用的代码的最小版本:
from sqlalchemy import create_engine
import os
from dotenv import load_dotenv
load_dotenv()
login_string = os.environ['login_string_proxy']
engine = create_engine(login_string, client_encoding="utf8", echo=True, connect_args={'options': '-csearch_path={}'.format("testing")})
engine.execute(f"INSERT INTO testing.mytable (product) VALUES ('123')")
pg8000: 它停止/等待的地方在 core.py:
def sock_read(b):
try:
return self._sock.read(b)
except OSError as e:
raise InterfaceError("network error on read") from e
我使用的代码的最小版本:
import pg8000
import os
from dotenv import load_dotenv
load_dotenv()
db_connection = pg8000.connect(database=os.environ['database'], host=os.environ['host'], port=os.environ['port'], user=os.environ['user'], password=os.environ['password'])
db_connection.run(f"INSERT INTO mytable (data) VALUES ('data')")
db_connection.commit()
db_connection.close()
对于我提到的所有示例,RDS 代理 中的日志看起来总是正常的 - 例如:
A new client connected from ...:60614.
Received Startup Message: [username="", database="", protocolMajorVersion=3, protocolMinorVersion=0, sslEnabled=false]
Proxy authentication with PostgreSQL native password authentication succeeded for user "" with TLS off.
A TCP connection was established from the proxy at ...:42795 to the database at ...:5432.
The new database connection successfully authenticated with TLS off.
我通过 RDS 和 RDS 代理上的安全组打开了所有端口,并在 VPC 内使用了 EC2。
我尝试打开和关闭自动提交。
所指的“命令行选项”是 -csearch_path={}
。
删除它,然后在建立连接后执行 set search_path = whatever
作为您的第一个查询。
这是一个已知问题,pg8000 无法连接到 AWS RDS 代理 (postgres)。我做了一个 PR https://github.com/tlocke/pg8000/pull/72 let see if Tony Locke (the father of pg8000) approves the change. ( if not you have to change the lines of the core.py https://github.com/tlocke/pg8000/pull/72/files )
self._write(FLUSH_MSG)
if (code != PASSWORD):
self._write(FLUSH_MSG)