Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP and pgbouncer in transaction mode: current transaction is aborted
    primarykey
    data
    text
    <p>I run a Drupal 7.2 web site embedding <a href="http://apps.facebook.com/video-preferans/" rel="nofollow">a flash game</a> with few custom PHP scripts for the player stats. Using CentOS 5.6/64 bit, PostgreSQL 8.4.8 and PHP 5.3. It is a Quad-Opteron with 4GB RAM.</p> <p>At the peak times (when there are around 500 players online) my web site used to went down with too many postmaster processes. On the advice of <a href="http://groups.google.com/group/pgsql.general/msg/21ce0df6a6023c79" rel="nofollow">pgsql-general mailing list</a> I have installed pgbouncer 1.3.4 with the following /etc/pgbouncer.ini:</p> <pre><code>[databases] pref = host=/tmp user=pref password=XXX dbname=pref [pgbouncer] logfile = /var/log/pgbouncer.log pidfile = /var/run/pgbouncer/pgbouncer.pid listen_port = 6432 unix_socket_dir = /tmp auth_type = md5 auth_file = /var/lib/pgsql/data/global/pg_auth pool_mode = transaction ;pool_mode = session server_check_delay = 10 max_client_conn = 200 default_pool_size = 16 log_connections = 0 log_disconnections = 0 log_pooler_errors = 1 </code></pre> <p>And have increased shared_buffers = 1024MB and decreased max_connections = 50 in postgresql.conf.</p> <p>This has helped, but I have often a problem that a prepared PDO statement won't be found:</p> <pre><code>SQLSTATE[26000]: Invalid sql statement name: 7 ERROR: prepared statement "pdo_stmt_00000016" does not exist </code></pre> <ul> <li>probably because pgbouncer switches the connection between a prepare() and execute().</li> </ul> <p>I can't switch pgbouncer to session mode - my web site will hang.</p> <p>I've tried adding <strong>PDO::ATTR_EMULATE_PREPARES => true</strong> - my web site hangs too.</p> <p>I've added beginTransaction() and commit() around each prepare() and execute() call - but then I get the following error very often:</p> <pre><code>SQLSTATE[25P02]: In failed sql transaction: 7 ERROR: current transaction is aborted, commands ignored until end of transaction block </code></pre> <p>Below is an excerpt of my code failing with that error - it is very straightforward and just calls five SELECT statements:</p> <pre><code>function fetch_top() { $table = ''; $top = ''; try { # throw exception on any errors $options = array(PDO::ATTR_ERRMODE =&gt; PDO::ERRMODE_EXCEPTION); $db = new PDO(sprintf('pgsql:host=%s port=%u; dbname=%s', DBHOST, DBPORT, DBNAME), DBUSER, DBPASS, $options); # last week's winner $db-&gt;beginTransaction(); $sth = $db-&gt;prepare(" select u.id, u.first_name, u.avatar, u.female, u.city, m.money, u.login &gt; u.logout as online from pref_users u, pref_money m where m.yw=to_char(current_timestamp - interval '1 week', 'IYYY-IW') and u.id=m.id order by m.money desc limit 1 "); $sth-&gt;execute(); $winner = $sth-&gt;fetch(PDO::FETCH_OBJ); $db-&gt;commit(); $db-&gt;beginTransaction(); $sth = $db-&gt;prepare(' select count(id) from ( select id, row_number() over(partition by yw order by money desc) as ranking from pref_money ) x where x.ranking = 1 and id=? '); $sth-&gt;execute(array($winner-&gt;id)); $winner_medals = $sth-&gt;fetchColumn(); $db-&gt;commit(); # current week leader $db-&gt;beginTransaction(); $sth = $db-&gt;prepare(" select u.id, u.first_name, u.avatar, u.female, u.city, m.money, u.login &gt; u.logout as online from pref_users u, pref_money m where m.yw=to_char(current_timestamp, 'IYYY-IW') and u.id=m.id order by m.money desc limit 1 "); $sth-&gt;execute(); $leader = $sth-&gt;fetch(PDO::FETCH_OBJ); $db-&gt;commit(); $db-&gt;beginTransaction(); $sth = $db-&gt;prepare(' select count(id) from ( select id, row_number() over(partition by yw order by money desc) as ranking from pref_money ) x where x.ranking = 1 and id=? '); $sth-&gt;execute(array($leader-&gt;id)); $leader_medals = $sth-&gt;fetchColumn(); $db-&gt;commit(); # fetch top players $db-&gt;beginTransaction(); $sth = $db-&gt;prepare(" select u.id, u.first_name, u.female, u.city, m.money, u.login &gt; u.logout as online from pref_users u, pref_money m where m.yw=to_char(current_timestamp, 'IYYY-IW') and u.id=m.id order by m.money desc limit 7 "); $sth-&gt;execute(); $i = 0; while ($player = $sth-&gt;fetch(PDO::FETCH_OBJ)) { $top .= user_link($player) . ($i++ &gt; 0 ? '' : '&amp;nbsp;&amp;raquo;') . '&lt;br /&gt;'; } $db-&gt;commit(); # create the HTML table $table = sprintf('.... skipped for brevity ....'); } catch (Exception $e) { exit('Database problem: ' . $e-&gt;getMessage()); } return $table; } </code></pre> <p>Any help please? Alex</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload