EnterpriseDB: The Enterprise Postgres Company Postgres Plus Forums: The PostgreSQL Open Source Database from EnterpriseDB
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 

PGPOOL: unnamed prepared statement does not exist  XML

Forum Index » Postgres Plus Cloud Database
Author Message
mbaird

Member

Joined: 3 Oct 2011 16:13:33
Messages: 22
Offline

I'm trying to run my Java app against a Cloud DB cluster (Postgres 9.1 64 bit) and I'm getting an error when I run against PGPool (port 9999). My app runs perfectly when running against port 5432, so I assume it has something to do with the PGPool configuration?

Here's the stack trace I get:


In the logs on the database server I just see a few lines like this one:


Other info about my app:
Vibhor_K

Senior member
[Avatar]

Joined: 3 Jul 2009 09:46:15
Messages: 518
Offline

My mistake... Please ignore my first response.

I think this was fixed in pgpool-II 3.0.3.

This message was edited 1 time. Last update was at 13 Mar 2012 15:27:46


Thanks & Regards,
Vibhor Kumar
Blog:http://vibhork.blogspot.com
[Email] [WWW]
mbaird

Member

Joined: 3 Oct 2011 16:13:33
Messages: 22
Offline

this is what I'm seeing on the server:



Are you sure it wasn't fixed in 3.0.4?
Gurjeet_S

Senior member

Joined: 2 Aug 2006 07:46:30
Messages: 101
Offline

This seems to have something to do with how your application is behaving, in combination with how pgpool is configured.

Whenever the application disconnects from pgpool, pgpool issues the command specified in reset_query_list parameter to the database connection that was associated with the application connection. By default, the reset_query_list parameter is set to 'ABORT; DISCARD ALL'

pgpool does so, so that the database connection can be reused and provided to the next incoming application connection, and so that the next connection does not see any changes done to the database session by the previous application connection. Changes to session may include the prepared statements , change of session level parameters using the SET command, presence of temporary table, etc. So performing a DISCARD ALL not only protects the next connection from getting wrong results, it also protects the security of the previous session.

Now, if your application issues a PREPARE command, and disconnects, and then connects again to perform EXECUTE on that prepared statement then it won't be able to find the statement since it has been discarded by the database in response to the DISCARD ALL performed by pgpool.

Hope it explains the behaviour you are seeing.

UPDATE: To configure reset_query_list to suit your application behaviour, please refere to Postgres' DISCARD statement documentation.

http://www.postgresql.org/docs/9.0/static/sql-discard.html

This message was edited 1 time. Last update was at 14 Mar 2012 11:23:06

mbaird

Member

Joined: 3 Oct 2011 16:13:33
Messages: 22
Offline

I cranked the logging way up and I don't see any disconnects happening between the prepare and the execute lines. I only see disconnects after the "unnamed prepared statement does not exist" error is thrown and the transaction is rolled back.
mbaird

Member

Joined: 3 Oct 2011 16:13:33
Messages: 22
Offline

I also tried setting reset_query_list='' and I still get the same error.
Gurjeet_S

Senior member

Joined: 2 Aug 2006 07:46:30
Messages: 101
Offline

Would it be possible for you to set the following parameters in postgresql.conf and reload the server config. Grab the server log, and turn them back off again:

Set
log_connections=on
log_disconnections=on
log_min_duration_statement=0

/etc/init.d/ppas-9.0 reload

Let the application run for a few minutes. Grab the postgres server log for this duration.

Disable the settings enabled above by commenting out the parameters (very important since they may affect performance)

And send reload signal again:

/etc/init.d/ppas-9.0 reload

Report what you see in the server logs here.

Thanks.
mbaird

Member

Joined: 3 Oct 2011 16:13:33
Messages: 22
Offline

I already did this and sent the log file to enterprise DB support. I don't think I'm comfortable posting all my app's SQL into this forum.
Gurjeet_S

Senior member

Joined: 2 Aug 2006 07:46:30
Messages: 101
Offline

Thank you. I'll ping support for the logs.

Just to make sure, you did have log_min_duration_statement set to 0 when you captured those logs. Right?

What I am trying to ascertain here is that pgpool does not send any ot its own statements between application's PREPARE and BIND statements. Because if pgpool does that, then Postgres will drop the unnamed prepared statement before the BIND call can happen.

This message was edited 1 time. Last update was at 14 Mar 2012 16:52:15

mbaird

Member

Joined: 3 Oct 2011 16:13:33
Messages: 22
Offline

I've gotten around this for now by adding the parameter protocolVersion=2 to the JDBC URL to force it to use the JDBC version 2 protocol, which prevents it from using server side prepared statements. I feel like this is more of a horrible hack to get around a serious PGPool limitation than an actual fix.

I posted more information here:
http://stackoverflow.com/questions/9725018/java-queries-against-pgpool-ii-cause-unnamed-prepared-statement-does-not-exist
Gurjeet_S

Senior member

Joined: 2 Aug 2006 07:46:30
Messages: 101
Offline

Just for the record, here's the conversation we had in private after looking at Postgres server logs.

Gurjeet_S wrote:
As I suspected in the forum post, pgpool is sending queries of its own between the application's PREPARE and BIND calls.

At both the instances in your log where you see this error, 'unnamed prepared statement does not exist', you can see a few lines above it that the application had parsed a query:

duration: 0.693 ms parse <unnamed>: SELECT

then pgpool sends its queries:

duration: 0.193 ms statement: SELECT count(*) FROM pg_class ...
...

And then we see application's bind message and the error:

ERROR: 26000: unnamed prepared statement does not exist
LOCATION: exec_bind_message, postgres.c:1444


On a PARSE (aka PREPARE) message Postgres creates an unnamed portal, and it drops this unnamed portal as son as it sees another query that does not use PARSE message.

By design, pgpool asks postgres database for the metadata of the tables involved in the query. Here pgpool is sending its metadata queries immediately after the PARSE message, hence causing Postgres to drop the just created unnamed portal. And when the application comes around to perform BIND operation on that unnamed statement, Postgres correctly says that there is no unnamed portal/statement in effect, because it has been dropped.

If you choose to deploy PPAS 9.1 clusters, (or in the next iteration of PG/PPAS 9.0 servers) then you should get pgpool 3.1 which alleviates the problem somewhat since in that version of pgpool, the cache size for table metadata has been increased from 32 to 128. You may still see this error, but not until you use more than 128 tables in your sessions.

Other, and a surefire, way to work around this would be to configure your application (or the ORM framework) to either not use unnamed PREPARE statements, or ti use named PREPARE statements.

Hope it clearly explains why you are seeing the problem.


mbaird wrote:
Gurjeet, thank you so much for looking at this. This issue makes sense to me now. I'm not sure how I should proceed though.

I'm currently using 64bit Postgres 9.1 open source. Are you saying that if I used Postgres Plus Advanced Server 9.1 that it would come with the newer version of PGPool? Is there any ETA on the open source version getting upgraded to the newer version of PGPool?

Also, I'm confused about the price difference of the open source Postgres versus Postgres Plus Advanced Server Cloud DB clusters. Are they the same price? Do I have to buy some extra PPAS licenses or something to use that version of Cloud DB?

I'd rather fix my app to always use named PREPARE statements, but I've just spent about an hour searching for a way to force Hibernate to use named PREPARE statements and I haven't found anything. Are you guys aware of a way to force Hibernate to name all prepare statements? The more I read the more I think this might actually be a JDBC thing that I have no control over, so I'm not sure there is a application side fix for this.

Gurjeet_S wrote:
Yes, Advanced Server 9.1 instances have the newer version of pgpool, which may solve your problem since it increases the metadata cache from 32 to 128. But if your application uses more than that many tables in a single session, then you will hit this error again.

Although the price is the same for the open source PostgreSQL and the Advanced Server version of cluster, I'd let Gary Carter answer this one and how they may differ in the future.

Typically, I have seen ORM frameworks PREPARE a statement for single use. That is, they perform PREPARE-BIND-EXECUTE-DISCARD for every statement they come across. Instead of helping improve performance (original intention of PREPARE-once EXECUTE-multiple-times pattern), this pattern actually hampers perfornance since the application is now doing 3 network round-trips for the same task that could be done in one network round-trip if it were to use unprepared statements.

So, if your application is performing the same PREPARE-BIND-EXECUTE-DISCARD pattern, then it might help in performance and getting rid of this error if you configure it to not use prepared statements at all.

Regards,


mbaird wrote:
Actually in reading up on this some more I've found that any parametrized query in JDBC, since JDBC version 3.0, seems to send these 3 prepare/bind/execute commands. Hibernate caches the prepared statement, so performance shouldn't be a big issue, but there is absolutely no way for me to remove these <unnamed> statements from my app. This is just how the Java JDBC driver for Postgres works.

What bothers me is that I've run my app against PGPool before without this issue. I don't understand why PGPool needs to be querying for table metadata if all it is being used for is a load balancer. Is there some PGPool configuration option that could turn off those metadata queries?
schevelev

Member

Joined: 28 Apr 2011 08:45:10
Messages: 12
Offline

Hello,

I have the same problem with unnamed prepared statements, I use Open Source PostgresSQL with pgpool 3.0.3. Do I inderstand correctly that the only way to have pgpool 3.1 now is to use Postgres Plus Advanced Server ?
Gurjeet_S

Senior member

Joined: 2 Aug 2006 07:46:30
Messages: 101
Offline

This problem and diagnosis was reported to the pgpool community and they have just applied a patch to resolve this [1].

This fix should be available in the next minor update to pgpool.

[1] http://www.pgpool.net/mantisbt/view.php?id=14
Gurjeet_S

Senior member

Joined: 2 Aug 2006 07:46:30
Messages: 101
Offline

Just for the record, the bug has been fixed in pgpool, and applied to all stable branches. See [1].

[1] http://www.pgpool.net/mantisbt/view.php?id=14#c102
Gary_C

Senior member

Joined: 17 Dec 2008 09:39:07
Messages: 265
Offline

This fix is now deployed on the US East and EU West Cluster Managers.
isalinas

New member

Joined: 30 Nov 2012 10:28:32
Messages: 5
Offline

I am getting now on the latest release of clouddb "ERROR: portal "" does not exist". I show in the below link this was fixed in 3.1.5 release of pgpool. But, currently clouddb is using 3.1.4, will the next stable release of pgpool be released to address this issue?


http://git.postgresql.org/gitweb/?p=pgpool2.git;a=commit;h=3e902fe700dae67018ae4c98e027d5d45299d6c6

Thanks!
 
Forum Index » Postgres Plus Cloud Database
Go to:   
Powered by JForum 2.1.8 © JForum Team