Changed error message for blocks by prepared transactions

Started by Andreas 'ads' Scherbaumover 16 years ago3 messages
#1Andreas 'ads' Scherbaum
adsmail@wars-nicht.de
1 attachment(s)

Hello,

the small attached patch changes the error message for a blocked
database in case there are prepared transactions. The original message
"accessed by other users" is misleading.

Example:

----- snip -----
postgres=# begin;
BEGIN
postgres=# prepare transaction 'abc';
PREPARE TRANSACTION
postgres=# \c template1
psql (8.4rc1)
Sie sind jetzt verbunden mit der Datenbank »template1«.
template1=# alter database postgres rename to test;
ERROR: database "postgres" is being blocked by prepared transactions
DETAIL: There are 1 prepared transaction(s) using the database.
----- snip -----

Translation still pending, how to add new messages to the .po files?

Kind regards

--
Andreas 'ads' Scherbaum
German PostgreSQL User Group
European PostgreSQL User Group - Board of Directors
Volunteer Regional Contact, Germany - PostgreSQL Project

PGDay.eu 2009 in Paris, Nov. 6/7, http://www.pgday.eu/

Attachments:

different_msg_for_prep_transactions.difftext/x-patch; name=different_msg_for_prep_transactions.diffDownload
Index: src/backend/commands/dbcommands.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/commands/dbcommands.c,v
retrieving revision 1.225
diff -u -3 -p -r1.225 dbcommands.c
--- src/backend/commands/dbcommands.c	11 Jun 2009 14:48:55 -0000	1.225
+++ src/backend/commands/dbcommands.c	22 Jun 2009 21:50:23 -0000
@@ -501,11 +501,24 @@ createdb(const CreatedbStmt *stmt)
 	 * throw one.
 	 */
 	if (CountOtherDBBackends(src_dboid, &notherbackends, &npreparedxacts))
-		ereport(ERROR,
-				(errcode(ERRCODE_OBJECT_IN_USE),
-			errmsg("source database \"%s\" is being accessed by other users",
-				   dbtemplate),
-				 errdetail_busy_db(notherbackends, npreparedxacts)));
+	{
+		if (npreparedxacts > 0)
+		{
+			ereport(ERROR,
+					(errcode(ERRCODE_OBJECT_IN_USE),
+				errmsg("source database \"%s\" is being blocked by prepared transactions",
+					   dbtemplate),
+					 errdetail_busy_db(notherbackends, npreparedxacts)));
+		}
+		else
+		{
+			ereport(ERROR,
+					(errcode(ERRCODE_OBJECT_IN_USE),
+				errmsg("source database \"%s\" is being accessed by other users",
+					   dbtemplate),
+					 errdetail_busy_db(notherbackends, npreparedxacts)));
+		}
+	}
 
 	/*
 	 * Select an OID for the new database, checking that it doesn't have a
@@ -799,11 +812,24 @@ dropdb(const char *dbname, bool missing_
 	 * As in CREATE DATABASE, check this after other error conditions.
 	 */
 	if (CountOtherDBBackends(db_id, &notherbackends, &npreparedxacts))
-		ereport(ERROR,
-				(errcode(ERRCODE_OBJECT_IN_USE),
-				 errmsg("database \"%s\" is being accessed by other users",
-						dbname),
-				 errdetail_busy_db(notherbackends, npreparedxacts)));
+	{
+		if (npreparedxacts > 0)
+		{
+			ereport(ERROR,
+					(errcode(ERRCODE_OBJECT_IN_USE),
+					 errmsg("database \"%s\" is being blocked by prepared transactions",
+							dbname),
+					 errdetail_busy_db(notherbackends, npreparedxacts)));
+		}
+		else
+		{
+			ereport(ERROR,
+					(errcode(ERRCODE_OBJECT_IN_USE),
+					 errmsg("database \"%s\" is being accessed by other users",
+							dbname),
+					 errdetail_busy_db(notherbackends, npreparedxacts)));
+		}
+	}
 
 	/*
 	 * Remove the database's tuple from pg_database.
@@ -940,11 +966,24 @@ RenameDatabase(const char *oldname, cons
 	 * As in CREATE DATABASE, check this after other error conditions.
 	 */
 	if (CountOtherDBBackends(db_id, &notherbackends, &npreparedxacts))
-		ereport(ERROR,
-				(errcode(ERRCODE_OBJECT_IN_USE),
-				 errmsg("database \"%s\" is being accessed by other users",
-						oldname),
-				 errdetail_busy_db(notherbackends, npreparedxacts)));
+	{
+		if (npreparedxacts > 0)
+		{
+			ereport(ERROR,
+					(errcode(ERRCODE_OBJECT_IN_USE),
+					 errmsg("database \"%s\" is being blocked by prepared transactions",
+							oldname),
+					 errdetail_busy_db(notherbackends, npreparedxacts)));
+		}
+		else
+		{
+			ereport(ERROR,
+					(errcode(ERRCODE_OBJECT_IN_USE),
+					 errmsg("database \"%s\" is being accessed by other users",
+							oldname),
+					 errdetail_busy_db(notherbackends, npreparedxacts)));
+		}
+	}
 
 	/* rename */
 	newtup = SearchSysCacheCopy(DATABASEOID,
@@ -1077,11 +1116,24 @@ movedb(const char *dbname, const char *t
 	 * As in CREATE DATABASE, check this after other error conditions.
 	 */
 	if (CountOtherDBBackends(db_id, &notherbackends, &npreparedxacts))
-		ereport(ERROR,
-				(errcode(ERRCODE_OBJECT_IN_USE),
-				 errmsg("database \"%s\" is being accessed by other users",
-						dbname),
-				 errdetail_busy_db(notherbackends, npreparedxacts)));
+	{
+		if (npreparedxacts > 0)
+		{
+			ereport(ERROR,
+					(errcode(ERRCODE_OBJECT_IN_USE),
+					 errmsg("database \"%s\" is being blocked by prepared transactions",
+							dbname),
+					 errdetail_busy_db(notherbackends, npreparedxacts)));
+		}
+		else
+		{
+			ereport(ERROR,
+					(errcode(ERRCODE_OBJECT_IN_USE),
+					 errmsg("database \"%s\" is being accessed by other users",
+							dbname),
+					 errdetail_busy_db(notherbackends, npreparedxacts)));
+		}
+	}
 
 	/*
 	 * Get old and new database paths
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andreas 'ads' Scherbaum (#1)
Re: Changed error message for blocks by prepared transactions

"Andreas 'ads' Scherbaum" <adsmail@wars-nicht.de> writes:

the small attached patch changes the error message for a blocked
database in case there are prepared transactions.

Isn't this duplicative of the errdetail_busy_db code? And anyway
I do not see a reason not to consider prepared transactions as
"other users".

regards, tom lane

#3Andreas 'ads' Scherbaum
adsmail@wars-nicht.de
In reply to: Tom Lane (#2)
Re: Changed error message for blocks by prepared transactions

On Mon, 22 Jun 2009 19:24:28 -0400 Tom Lane wrote:

"Andreas 'ads' Scherbaum" <adsmail@wars-nicht.de> writes:

the small attached patch changes the error message for a blocked
database in case there are prepared transactions.

Isn't this duplicative of the errdetail_busy_db code? And anyway
I do not see a reason not to consider prepared transactions as
"other users".

Because you know the details.
Most other users check pg_stat_activity just to find out there is no
other user connected. A prepared transaction is not a connected user,
so the error message is still misleading.

You are right with the errdetail_busy_db(), but that's only true for
8.4, not for earlier versions. In addition that's only true if you
haven't supressed the hints like some scripts do (-q as example).

Bye

--
Andreas 'ads' Scherbaum
German PostgreSQL User Group
European PostgreSQL User Group - Board of Directors
Volunteer Regional Contact, Germany - PostgreSQL Project

PGDay.eu 2009 in Paris, Nov. 6/7, http://www.pgday.eu/