-
Notifications
You must be signed in to change notification settings - Fork 9
How to Resolve Issue with Prepared Statements: 'Statement Already Exists' on Server Deployment #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@akanksha314e Hello! Could you please add more details about your PostgreSQL setup on the server? Maybe you have PGBouncer and/or Patroni? |
It looks like you have some custom setup on the server. |
The queries are being executed like this:
|
@akanksha314e What about PostgreSQL setup? I've checked right now, and if you specify |
Hello @chandr-andr , We have identified the cause of the issue. It occurs specifically when we use the Supavisor DB link instead of directly connecting to the PostgreSQL server. Is there any issue with using connection pooler in general or any configuration you know which need to be done? We have been using asyncpg with supavisor and not encountered this issue before. |
@akanksha314e Hello! There are some problems with the external connection pool. I recommend checking again if you have queries with |
Hello @chandr-andr, Thank you for the suggestion. I tried using |
@akanksha314e It's really strange, are you sure you set |
@chandr-andr Yes, I have ensured that |
Okay, I'll deploy Supavisor DB and check PSQLPy with it. |
@akanksha314e Could you please tell me the version of Supavisor DB and maybe you have a configuration file to reproduce the problem? |
|
@akanksha314e Thanks, will check soon |
@akanksha314e One more thing which I've missed it @asynccontextmanager
async def get_db(pg_dsn: str) -> AsyncGenerator[Connection, None]:
db_pool = ConnectionPool(dsn=pg_dsn)
conn = await db_pool.connection()
try:
yield conn
finally:
db_pool.close() Each time you call the |
Hi, @chandr-andr is there any update on using transaction mode with Supavisor DB. |
Hi @chandr-andr is there a way to use transaction mode with Supavisor DB currently supported by psqlpy? |
@akanksha314e Hello! I've tested psqlpy with Supavisor DB and cannot reproduce your problem, I'll try one more time when I have time. Did you try to change your |
Hi @chandr-andr even with the global declaration the issue persists. Try executing the same query multiple times using a Supavisor connection. Sometimes its getting executed for the first time but fails when tried multiple times. Here's a sample code snippet that demonstrates the issue:
Following is the error log : |
@akanksha314e Thanks! I'll have time to continue researching this problem only on weekends. I'll come back here on Saturday/Sunday |
@chandr-andr Sure, thanks. |
Hi, @chandr-andr Is there any update on this issue ? |
@akanksha314e Hello! Thanks for finding this problem! I'll text u when it's fixed. For now, just use session mode in supavisor - it will be fine. |
Hi @chandr-andr I understand you may have a lot on your plate, but I was wondering if there’s any update or if this issue is planned for an upcoming release. If it might take some time, would you be open to me contributing a fix? If so, could you please point me to the relevant file(s) or logic where the changes would need to be made? I’d be happy to open a PR for your review. |
@akanksha314e Hello! Just yesterday, I found how to fix it completely and started implementing it here - #131 I have non-working days since Thursday, so by the end of the week, there will be a release that fixes your problem and I think some interesting things also. |
@chandr-andr Great, Thanks. |
@akanksha314e Hello! Here are some updates for you: I've supported external connection pools like PgBouncer and SupaVisor. So, the new release will be next week. For now, you can build psqlpy locally from this branch and test it. |
@akanksha314e Hello! There is a new release https://github.com/psqlpy-python/psqlpy/releases/tag/0.10.0 Please read the documentation related to external connection pools: https://psqlpy-python.github.io/external_connection_pools.html I'm rly waiting for u feedback, thank u! |
@akanksha314e Hello! Did you test it already? |
When deploying my code using psqlpy on the server, I am encountering an intermittent issue where queries fail with the error cannot prepare statement: statement already exists. However, the same APIs work fine in the local environment. After a few retries, the queries run as expected.
I have tried the following to troubleshoot the issue:
Despite these changes, the issue persists. The problem appears intermittently, failing a couple of times and then succeeding.
Code Context: The code executes queries using psqlpy and JinjaSQL for preparing the queries from templates. Here's the relevant part of the code:
sample code :
`@asynccontextmanager
async def get_db(pg_dsn: str) -> AsyncGenerator[Connection, None]:
`
The text was updated successfully, but these errors were encountered: