PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "access/htup_details.h"
#include "access/xact.h"
#include "catalog/pg_user_mapping.h"
#include "commands/defrem.h"
#include "funcapi.h"
#include "libpq/libpq-be.h"
#include "libpq/libpq-be-fe-helpers.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "postgres_fdw.h"
#include "storage/fd.h"
#include "storage/latch.h"
#include "utils/builtins.h"
#include "utils/datetime.h"
#include "utils/hsearch.h"
#include "utils/inval.h"
#include "utils/memutils.h"
#include "utils/syscache.h"
Go to the source code of this file.
Data Structures | |
struct | ConnCacheEntry |
Macros | |
#define | CONNECTION_CLEANUP_TIMEOUT 30000 |
#define | CONSTRUCT_ABORT_COMMAND(sql, entry, toplevel) |
#define | POSTGRES_FDW_GET_CONNECTIONS_COLS 2 |
Typedefs | |
typedef Oid | ConnCacheKey |
typedef struct ConnCacheEntry | ConnCacheEntry |
Variables | |
static HTAB * | ConnectionHash = NULL |
static unsigned int | cursor_number = 0 |
static unsigned int | prep_stmt_number = 0 |
static bool | xact_got_connection = false |
#define CONNECTION_CLEANUP_TIMEOUT 30000 |
Definition at line 91 of file connection.c.
#define CONSTRUCT_ABORT_COMMAND | ( | sql, | |
entry, | |||
toplevel | |||
) |
Definition at line 94 of file connection.c.
#define POSTGRES_FDW_GET_CONNECTIONS_COLS 2 |
typedef struct ConnCacheEntry ConnCacheEntry |
typedef Oid ConnCacheKey |
Definition at line 51 of file connection.c.
|
static |
Definition at line 727 of file connection.c.
References ConnCacheEntry::changing_xact_state, ConnCacheEntry::conn, DEBUG3, do_sql_command(), elog(), GetCurrentTransactionNestLevel(), IsolationIsSerializable, snprintf, and ConnCacheEntry::xact_depth.
Referenced by GetConnection().
|
static |
Definition at line 605 of file connection.c.
References be_gssapi_get_delegation(), ereport, errcode(), errdetail(), errmsg(), ERROR, i, MyProcPort, superuser_arg(), user, UserMappingPasswordRequired(), and values.
Referenced by connect_pg_server().
|
static |
Definition at line 648 of file connection.c.
References conn, do_sql_command(), and PQserverVersion().
Referenced by connect_pg_server().
|
static |
Definition at line 435 of file connection.c.
References check_conn_params(), configure_remote_session(), conn, CONNECTION_OK, ereport, errcode(), errdetail_internal(), errmsg(), ERROR, ExtractConnectionOptions(), GetDatabaseEncodingName(), i, libpqsrv_connect_params(), libpqsrv_disconnect(), list_length(), ForeignServer::options, palloc(), pchomp(), pfree(), PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, pgfdw_application_name, pgfdw_security_check(), PQerrorMessage(), PQstatus(), process_pgfdw_appname(), ForeignServer::servername, user, values, and WAIT_EVENT_EXTENSION.
Referenced by make_new_connection().
Definition at line 2164 of file connection.c.
References Assert(), ConnCacheEntry::conn, ConnectionHash, DEBUG3, disconnect_pg_server(), elog(), ereport, errmsg(), FSV_MISSING_OK, GetForeignServerExtended(), hash_seq_init(), hash_seq_search(), ConnCacheEntry::invalidated, OidIsValid, ConnCacheEntry::serverid, ForeignServer::servername, WARNING, and ConnCacheEntry::xact_depth.
Referenced by postgres_fdw_disconnect(), and postgres_fdw_disconnect_all().
|
static |
Definition at line 567 of file connection.c.
References ConnCacheEntry::conn, and libpqsrv_disconnect().
Referenced by disconnect_cached_connections(), GetConnection(), pgfdw_inval_callback(), pgfdw_reject_incomplete_xact_state_change(), and pgfdw_reset_xact_state().
void do_sql_command | ( | PGconn * | conn, |
const char * | sql | ||
) |
Definition at line 684 of file connection.c.
References conn, do_sql_command_begin(), and do_sql_command_end().
Referenced by begin_remote_xact(), configure_remote_session(), pgfdw_subxact_callback(), pgfdw_xact_callback(), and postgresExecForeignTruncate().
|
static |
Definition at line 691 of file connection.c.
References conn, ERROR, pgfdw_report_error(), and PQsendQuery().
Referenced by do_sql_command(), pgfdw_subxact_callback(), and pgfdw_xact_callback().
Definition at line 698 of file connection.c.
References conn, ERROR, pgfdw_get_result(), pgfdw_report_error(), PGRES_COMMAND_OK, PQclear(), PQconsumeInput(), PQresultStatus(), and res.
Referenced by do_sql_command(), pgfdw_finish_pre_commit_cleanup(), and pgfdw_finish_pre_subcommit_cleanup().
PGconn* GetConnection | ( | UserMapping * | user, |
bool | will_prep_stmt, | ||
PgFdwConnState ** | state | ||
) |
Definition at line 172 of file connection.c.
References Assert(), begin_remote_xact(), CacheRegisterSyscacheCallback(), ConnCacheEntry::conn, CONNECTION_BAD, ConnectionHash, CopyErrorData(), CurrentMemoryContext, DEBUG3, disconnect_pg_server(), elog(), HASHCTL::entrysize, ereport, errdetail_internal(), errmsg_internal(), FlushErrorState(), FOREIGNSERVEROID, FreeErrorData(), HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), ConnCacheEntry::have_prep_stmt, ConnCacheEntry::invalidated, sort-test::key, HASHCTL::keysize, make_new_connection(), MemoryContextSwitchTo(), pchomp(), PgFdwConnState::pendingAreq, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, pgfdw_inval_callback(), pgfdw_reject_incomplete_xact_state_change(), pgfdw_subxact_callback(), pgfdw_xact_callback(), PQerrorMessage(), PQstatus(), process_pending_request(), RegisterSubXactCallback(), RegisterXactCallback(), ErrorData::sqlerrcode, ConnCacheEntry::state, user, USERMAPPINGOID, ConnCacheEntry::xact_depth, and xact_got_connection.
Referenced by create_foreign_modify(), dumpDatabase(), dumpDatabaseConfig(), dumpLOs(), dumpTableData_copy(), estimate_path_cost_size(), expand_extension_name_patterns(), expand_foreign_server_name_patterns(), expand_schema_name_patterns(), expand_table_name_patterns(), getTables(), main(), postgresAcquireSampleRowsFunc(), postgresAnalyzeForeignTable(), postgresBeginDirectModify(), postgresBeginForeignScan(), postgresExecForeignTruncate(), postgresGetAnalyzeInfoForForeignTable(), postgresImportForeignSchema(), setup_connection(), StartLogStreamer(), StreamLog(), and StreamLogicalLog().
unsigned int GetCursorNumber | ( | PGconn * | conn | ) |
Definition at line 791 of file connection.c.
References cursor_number.
Referenced by postgresAcquireSampleRowsFunc(), and postgresBeginForeignScan().
unsigned int GetPrepStmtNumber | ( | PGconn * | conn | ) |
Definition at line 805 of file connection.c.
References prep_stmt_number.
Referenced by prepare_foreign_modify().
|
static |
Definition at line 331 of file connection.c.
References Assert(), ConnCacheEntry::changing_xact_state, ConnCacheEntry::conn, connect_pg_server(), DEBUG3, defGetBoolean(), DefElem::defname, elog(), FOREIGNSERVEROID, GetForeignServer(), GetSysCacheHashValue1, ConnCacheEntry::have_error, ConnCacheEntry::have_prep_stmt, ConnCacheEntry::invalidated, ConnCacheEntry::keep_connections, lfirst, ConnCacheEntry::mapping_hashvalue, ObjectIdGetDatum(), ForeignServer::options, ConnCacheEntry::parallel_abort, ConnCacheEntry::parallel_commit, ConnCacheEntry::server_hashvalue, ConnCacheEntry::serverid, ForeignServer::serverid, ForeignServer::servername, ConnCacheEntry::state, user, USERMAPPINGOID, and ConnCacheEntry::xact_depth.
Referenced by GetConnection().
PG_FUNCTION_INFO_V1 | ( | postgres_fdw_disconnect | ) |
PG_FUNCTION_INFO_V1 | ( | postgres_fdw_disconnect_all | ) |
PG_FUNCTION_INFO_V1 | ( | postgres_fdw_get_connections | ) |
|
static |
Definition at line 1619 of file connection.c.
References ConnCacheEntry::changing_xact_state, ConnCacheEntry::conn, CONSTRUCT_ABORT_COMMAND, ConnCacheEntry::have_error, ConnCacheEntry::have_prep_stmt, in_error_recursion_trouble(), PgFdwConnState::pendingAreq, pgfdw_cancel_query(), pgfdw_exec_cleanup_query(), PQTRANS_ACTIVE, PQtransactionStatus(), and ConnCacheEntry::state.
Referenced by pgfdw_subxact_callback(), and pgfdw_xact_callback().
|
static |
Definition at line 1693 of file connection.c.
References ConnCacheEntry::changing_xact_state, ConnCacheEntry::conn, CONSTRUCT_ABORT_COMMAND, ConnCacheEntry::have_error, in_error_recursion_trouble(), lappend(), pgfdw_cancel_query_begin(), pgfdw_exec_cleanup_query_begin(), PQTRANS_ACTIVE, and PQtransactionStatus().
Referenced by pgfdw_subxact_callback(), and pgfdw_xact_callback().
Definition at line 1348 of file connection.c.
References conn, CONNECTION_CLEANUP_TIMEOUT, GetCurrentTimestamp(), pgfdw_cancel_query_begin(), pgfdw_cancel_query_end(), and TimestampTzPlusMilliseconds.
Referenced by pgfdw_abort_cleanup().
Definition at line 1365 of file connection.c.
References conn, ereport, errcode(), errmsg(), PQcancel(), PQfreeCancel(), PQgetCancel(), and WARNING.
Referenced by pgfdw_abort_cleanup_begin(), and pgfdw_cancel_query().
|
static |
Definition at line 1392 of file connection.c.
References conn, ereport, errcode(), errmsg(), pchomp(), pgfdw_get_cleanup_result(), PQclear(), PQconsumeInput(), PQerrorMessage(), and WARNING.
Referenced by pgfdw_cancel_query(), and pgfdw_finish_abort_cleanup().
|
static |
Definition at line 1444 of file connection.c.
References conn, CONNECTION_CLEANUP_TIMEOUT, GetCurrentTimestamp(), pgfdw_exec_cleanup_query_begin(), pgfdw_exec_cleanup_query_end(), and TimestampTzPlusMilliseconds.
Referenced by pgfdw_abort_cleanup().
Definition at line 1464 of file connection.c.
References conn, pgfdw_report_error(), PQsendQuery(), and WARNING.
Referenced by pgfdw_abort_cleanup_begin(), pgfdw_exec_cleanup_query(), and pgfdw_finish_abort_cleanup().
|
static |
Definition at line 1480 of file connection.c.
References conn, ereport, errcontext, errmsg(), pgfdw_get_cleanup_result(), pgfdw_report_error(), PGRES_COMMAND_OK, PQclear(), PQconsumeInput(), PQresultStatus(), and WARNING.
Referenced by pgfdw_exec_cleanup_query(), and pgfdw_finish_abort_cleanup().
PGresult* pgfdw_exec_query | ( | PGconn * | conn, |
const char * | query, | ||
PgFdwConnState * | state | ||
) |
Definition at line 818 of file connection.c.
References conn, ERROR, pgfdw_get_result(), pgfdw_report_error(), PQsendQuery(), and process_pending_request().
Referenced by close_cursor(), deallocate_query(), fetch_more_data(), get_remote_estimate(), postgresAcquireSampleRowsFunc(), postgresAnalyzeForeignTable(), postgresGetAnalyzeInfoForForeignTable(), postgresImportForeignSchema(), and postgresReScanForeignScan().
|
static |
Definition at line 1855 of file connection.c.
References Assert(), ConnCacheEntry::changing_xact_state, ConnCacheEntry::conn, CONNECTION_CLEANUP_TIMEOUT, CONSTRUCT_ABORT_COMMAND, GetCurrentTimestamp(), ConnCacheEntry::have_error, ConnCacheEntry::have_prep_stmt, lappend(), lfirst, NIL, PgFdwConnState::pendingAreq, pgfdw_cancel_query_end(), pgfdw_exec_cleanup_query_begin(), pgfdw_exec_cleanup_query_end(), pgfdw_reset_xact_state(), ConnCacheEntry::state, and TimestampTzPlusMilliseconds.
Referenced by pgfdw_subxact_callback(), and pgfdw_xact_callback().
|
static |
Definition at line 1747 of file connection.c.
References Assert(), ConnCacheEntry::changing_xact_state, ConnCacheEntry::conn, CONNECTION_BAD, do_sql_command_end(), ConnCacheEntry::have_error, ConnCacheEntry::have_prep_stmt, lappend(), lfirst, NIL, pgfdw_reset_xact_state(), PQclear(), PQgetResult(), PQsendQuery(), PQstatus(), and res.
Referenced by pgfdw_xact_callback().
|
static |
Definition at line 1821 of file connection.c.
References Assert(), ConnCacheEntry::changing_xact_state, ConnCacheEntry::conn, do_sql_command_end(), lfirst, pgfdw_reset_xact_state(), and snprintf.
Referenced by pgfdw_subxact_callback().
|
static |
Definition at line 1535 of file connection.c.
References CHECK_FOR_INTERRUPTS, conn, exit(), GetCurrentTimestamp(), MyLatch, now(), PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, PQclear(), PQconsumeInput(), PQgetResult(), PQisBusy(), PQsocket(), res, ResetLatch(), TimestampDifferenceMilliseconds(), WAIT_EVENT_EXTENSION, WaitLatchOrSocket(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, WL_SOCKET_READABLE, and WL_TIMEOUT.
Referenced by pgfdw_cancel_query_end(), and pgfdw_exec_cleanup_query_end().
Definition at line 846 of file connection.c.
References CHECK_FOR_INTERRUPTS, conn, ERROR, MyLatch, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, pgfdw_report_error(), PQclear(), PQconsumeInput(), PQgetResult(), PQisBusy(), PQsocket(), res, ResetLatch(), WAIT_EVENT_EXTENSION, WaitLatchOrSocket(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, and WL_SOCKET_READABLE.
Referenced by create_cursor(), do_sql_command_end(), execute_dml_stmt(), execute_foreign_modify(), fetch_more_data(), pgfdw_exec_query(), and prepare_foreign_modify().
Definition at line 1229 of file connection.c.
References Assert(), ConnCacheEntry::conn, ConnectionHash, DEBUG3, disconnect_pg_server(), elog(), FOREIGNSERVEROID, hash_seq_init(), hash_seq_search(), ConnCacheEntry::invalidated, ConnCacheEntry::mapping_hashvalue, ConnCacheEntry::server_hashvalue, USERMAPPINGOID, and ConnCacheEntry::xact_depth.
Referenced by GetConnection().
|
static |
Definition at line 1279 of file connection.c.
References ConnCacheEntry::changing_xact_state, ConnCacheEntry::conn, disconnect_pg_server(), ereport, errcode(), errmsg(), ERROR, GetForeignServer(), ConnCacheEntry::serverid, and ForeignServer::servername.
Referenced by GetConnection(), pgfdw_subxact_callback(), and pgfdw_xact_callback().
Definition at line 911 of file connection.c.
References conn, ereport, errcode(), errcontext, errdetail_internal(), errhint(), errmsg(), errmsg_internal(), MAKE_SQLSTATE, pchomp(), PG_DIAG_CONTEXT, PG_DIAG_MESSAGE_DETAIL, PG_DIAG_MESSAGE_HINT, PG_DIAG_MESSAGE_PRIMARY, PG_DIAG_SQLSTATE, PG_END_TRY, PG_FINALLY, PG_TRY, PQclear(), PQerrorMessage(), PQresultErrorField(), and res.
Referenced by close_cursor(), create_cursor(), deallocate_query(), do_sql_command_begin(), do_sql_command_end(), execute_dml_stmt(), execute_foreign_modify(), fetch_more_data(), fetch_more_data_begin(), get_remote_estimate(), pgfdw_exec_cleanup_query_begin(), pgfdw_exec_cleanup_query_end(), pgfdw_exec_query(), pgfdw_get_result(), postgresAcquireSampleRowsFunc(), postgresAnalyzeForeignTable(), postgresForeignAsyncNotify(), postgresGetAnalyzeInfoForForeignTable(), postgresImportForeignSchema(), postgresReScanForeignScan(), and prepare_foreign_modify().
|
static |
Definition at line 1303 of file connection.c.
References ConnCacheEntry::changing_xact_state, ConnCacheEntry::conn, CONNECTION_OK, DEBUG3, disconnect_pg_server(), elog(), ConnCacheEntry::invalidated, ConnCacheEntry::keep_connections, PQstatus(), PQTRANS_IDLE, PQtransactionStatus(), and ConnCacheEntry::xact_depth.
Referenced by pgfdw_finish_abort_cleanup(), pgfdw_finish_pre_commit_cleanup(), pgfdw_finish_pre_subcommit_cleanup(), pgfdw_subxact_callback(), and pgfdw_xact_callback().
|
static |
Definition at line 397 of file connection.c.
References be_gssapi_get_delegation(), conn, ereport, errcode(), errdetail(), errhint(), errmsg(), ERROR, i, MyProcPort, PQconnectionUsedGSSAPI(), PQconnectionUsedPassword(), superuser_arg(), user, UserMappingPasswordRequired(), and values.
Referenced by connect_pg_server().
|
static |
Definition at line 1116 of file connection.c.
References Assert(), ConnCacheEntry::changing_xact_state, ConnCacheEntry::conn, ConnectionHash, do_sql_command(), do_sql_command_begin(), elog(), ERROR, GetCurrentTransactionNestLevel(), hash_seq_init(), hash_seq_search(), lappend(), NIL, ConnCacheEntry::parallel_abort, ConnCacheEntry::parallel_commit, pgfdw_abort_cleanup(), pgfdw_abort_cleanup_begin(), pgfdw_finish_abort_cleanup(), pgfdw_finish_pre_subcommit_cleanup(), pgfdw_reject_incomplete_xact_state_change(), pgfdw_reset_xact_state(), snprintf, SUBXACT_EVENT_ABORT_SUB, SUBXACT_EVENT_PRE_COMMIT_SUB, ConnCacheEntry::xact_depth, and xact_got_connection.
Referenced by GetConnection().
|
static |
Definition at line 967 of file connection.c.
References Assert(), ConnCacheEntry::changing_xact_state, ConnCacheEntry::conn, ConnectionHash, cursor_number, DEBUG3, do_sql_command(), do_sql_command_begin(), elog(), ereport, errcode(), errmsg(), ERROR, hash_seq_init(), hash_seq_search(), ConnCacheEntry::have_error, ConnCacheEntry::have_prep_stmt, lappend(), NIL, ConnCacheEntry::parallel_abort, ConnCacheEntry::parallel_commit, pgfdw_abort_cleanup(), pgfdw_abort_cleanup_begin(), pgfdw_finish_abort_cleanup(), pgfdw_finish_pre_commit_cleanup(), pgfdw_reject_incomplete_xact_state_change(), pgfdw_reset_xact_state(), PQclear(), PQexec(), res, ConnCacheEntry::xact_depth, XACT_EVENT_ABORT, XACT_EVENT_COMMIT, XACT_EVENT_PARALLEL_ABORT, XACT_EVENT_PARALLEL_COMMIT, XACT_EVENT_PARALLEL_PRE_COMMIT, XACT_EVENT_PRE_COMMIT, XACT_EVENT_PRE_PREPARE, XACT_EVENT_PREPARE, and xact_got_connection.
Referenced by GetConnection().
Datum postgres_fdw_disconnect | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2115 of file connection.c.
References disconnect_cached_connections(), GetForeignServerByName(), PG_GETARG_TEXT_PP, PG_RETURN_BOOL, ForeignServer::serverid, and text_to_cstring().
Datum postgres_fdw_disconnect_all | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2136 of file connection.c.
References disconnect_cached_connections(), InvalidOid, and PG_RETURN_BOOL.
Datum postgres_fdw_get_connections | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2026 of file connection.c.
References Assert(), BoolGetDatum(), ConnectionHash, CStringGetTextDatum, FSV_MISSING_OK, GetForeignServerExtended(), hash_seq_init(), hash_seq_search(), InitMaterializedSRF(), PG_RETURN_VOID, POSTGRES_FDW_GET_CONNECTIONS_COLS, ForeignServer::servername, ReturnSetInfo::setDesc, ReturnSetInfo::setResult, tuplestore_putvalues(), and values.
void ReleaseConnection | ( | PGconn * | conn | ) |
Definition at line 770 of file connection.c.
Referenced by estimate_path_cost_size(), finish_foreign_modify(), postgresAcquireSampleRowsFunc(), postgresAnalyzeForeignTable(), postgresEndDirectModify(), postgresEndForeignScan(), postgresGetAnalyzeInfoForForeignTable(), and postgresImportForeignSchema().
|
static |
Definition at line 581 of file connection.c.
References defGetBoolean(), DefElem::defname, lfirst, and user.
Referenced by check_conn_params(), and pgfdw_security_check().
|
static |
Definition at line 77 of file connection.c.
Referenced by disconnect_cached_connections(), GetConnection(), pgfdw_inval_callback(), pgfdw_subxact_callback(), pgfdw_xact_callback(), and postgres_fdw_get_connections().
|
static |
Definition at line 80 of file connection.c.
Referenced by close_cursor(), GetCursorNumber(), pgfdw_xact_callback(), and postgresAcquireSampleRowsFunc().
|
static |
Definition at line 81 of file connection.c.
Referenced by GetPrepStmtNumber().
Definition at line 84 of file connection.c.
Referenced by GetConnection(), pgfdw_subxact_callback(), and pgfdw_xact_callback().