Skip to content
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

Create/Drop database not visible in the pg_stat_statements view #114

Open
wants to merge 11 commits into
base: BABEL_3_X_DEV__PG_15_X
Choose a base branch
from
16 changes: 14 additions & 2 deletions src/backend/tcop/utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@

/* Hook for plugins to get control in ProcessUtility() */
ProcessUtility_hook_type ProcessUtility_hook = NULL;
CreateDbStmt_hook_type CreateDbStmt_hook = NULL;
DropDbStmt_hook_type DropDbStmt_hook = NULL;

/* local function declarations */
static int ClassifyUtilityCommandAsReadOnly(Node *parsetree);
Expand Down Expand Up @@ -778,8 +780,13 @@ standard_ProcessUtility(PlannedStmt *pstmt,
*/
if (sql_dialect != SQL_DIALECT_TSQL) {
PreventInTransactionBlock(isTopLevel, "CREATE DATABASE");
kritika-0601 marked this conversation as resolved.
Show resolved Hide resolved
createdb(pstate, (CreatedbStmt *) parsetree);
}
else
{
if (CreateDbStmt_hook)
(*CreateDbStmt_hook)(pstate, pstmt);
}
createdb(pstate, (CreatedbStmt *) parsetree);
break;

case T_AlterDatabaseStmt:
Expand All @@ -804,8 +811,13 @@ standard_ProcessUtility(PlannedStmt *pstmt,
*/
if (sql_dialect != SQL_DIALECT_TSQL) {
PreventInTransactionBlock(isTopLevel, "DROP DATABASE");
kritika-0601 marked this conversation as resolved.
Show resolved Hide resolved
DropDatabase(pstate, (DropdbStmt *) parsetree);
}
else
{
if (DropDbStmt_hook)
(*DropDbStmt_hook)(pstmt);
}
DropDatabase(pstate, (DropdbStmt *) parsetree);
break;

/* Query-level asynchronous notification */
Expand Down
7 changes: 7 additions & 0 deletions src/include/tcop/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#ifndef UTILITY_H
#define UTILITY_H

#include "parser/parse_node.h"
#include "tcop/cmdtag.h"
#include "tcop/tcopprot.h"

Expand Down Expand Up @@ -109,4 +110,10 @@ extern LogStmtLevel GetCommandLogLevel(Node *parsetree);

extern bool CommandIsReadOnly(PlannedStmt *pstmt);

typedef void (*CreateDbStmt_hook_type)(ParseState *pstate, PlannedStmt *pstmt);
extern PGDLLIMPORT CreateDbStmt_hook_type CreateDbStmt_hook;

typedef void (*DropDbStmt_hook_type)(PlannedStmt *pstmt);
extern PGDLLIMPORT DropDbStmt_hook_type DropDbStmt_hook;

#endif /* UTILITY_H */