PostgreSQL Source Code git master
|
#include "postgres_fe.h"
#include <limits.h>
#include <time.h>
#include "catalog/pg_am_d.h"
#include "catalog/pg_class_d.h"
#include "catalog/pg_namespace_d.h"
#include "common/logging.h"
#include "common/username.h"
#include "fe_utils/cancel.h"
#include "fe_utils/option_utils.h"
#include "fe_utils/parallel_slot.h"
#include "fe_utils/query_utils.h"
#include "fe_utils/simple_list.h"
#include "fe_utils/string_utils.h"
#include "getopt_long.h"
#include "pgtime.h"
#include "storage/block.h"
Go to the source code of this file.
Data Structures | |
struct | PatternInfo |
struct | PatternInfoArray |
struct | AmcheckOptions |
struct | DatabaseInfo |
struct | RelationInfo |
Macros | |
#define | log_no_match(...) |
#define | FREE_AND_SET_NULL(x) |
#define | VERBOSE_DATNAME_LENGTH 35 |
Typedefs | |
typedef struct PatternInfo | PatternInfo |
typedef struct PatternInfoArray | PatternInfoArray |
typedef struct AmcheckOptions | AmcheckOptions |
typedef struct DatabaseInfo | DatabaseInfo |
typedef struct RelationInfo | RelationInfo |
Functions | |
static void | prepare_heap_command (PQExpBuffer sql, RelationInfo *rel, PGconn *conn) |
static void | prepare_btree_command (PQExpBuffer sql, RelationInfo *rel, PGconn *conn) |
static void | run_command (ParallelSlot *slot, const char *sql) |
static bool | verify_heap_slot_handler (PGresult *res, PGconn *conn, void *context) |
static bool | verify_btree_slot_handler (PGresult *res, PGconn *conn, void *context) |
static void | help (const char *progname) |
static void | progress_report (uint64 relations_total, uint64 relations_checked, uint64 relpages_total, uint64 relpages_checked, const char *datname, bool force, bool finished) |
static void | append_database_pattern (PatternInfoArray *pia, const char *pattern, int encoding) |
static void | append_schema_pattern (PatternInfoArray *pia, const char *pattern, int encoding) |
static void | append_relation_pattern (PatternInfoArray *pia, const char *pattern, int encoding) |
static void | append_heap_pattern (PatternInfoArray *pia, const char *pattern, int encoding) |
static void | append_btree_pattern (PatternInfoArray *pia, const char *pattern, int encoding) |
static void | compile_database_list (PGconn *conn, SimplePtrList *databases, const char *initial_dbname) |
static void | compile_relation_list_one_db (PGconn *conn, SimplePtrList *relations, const DatabaseInfo *dat, uint64 *pagecount) |
int | main (int argc, char *argv[]) |
static bool | should_processing_continue (PGresult *res) |
static char * | indent_lines (const char *str) |
static PatternInfo * | extend_pattern_info_array (PatternInfoArray *pia) |
static void | append_relation_pattern_helper (PatternInfoArray *pia, const char *pattern, int encoding, bool heap_only, bool btree_only) |
static bool | append_db_pattern_cte (PQExpBuffer buf, const PatternInfoArray *pia, PGconn *conn, bool inclusive) |
static void | append_rel_pattern_raw_cte (PQExpBuffer buf, const PatternInfoArray *pia, PGconn *conn) |
static void | append_rel_pattern_filtered_cte (PQExpBuffer buf, const char *raw, const char *filtered, PGconn *conn) |
Variables | |
static AmcheckOptions | opts |
static const char * | progname = NULL |
static bool | all_checks_pass = true |
static pg_time_t | last_progress_report = 0 |
static bool | progress_since_last_stderr = false |
static const char *const | amcheck_sql |
#define FREE_AND_SET_NULL | ( | x | ) |
#define log_no_match | ( | ... | ) |
Definition at line 207 of file pg_amcheck.c.
#define VERBOSE_DATNAME_LENGTH 35 |
typedef struct AmcheckOptions AmcheckOptions |
typedef struct DatabaseInfo DatabaseInfo |
typedef struct PatternInfo PatternInfo |
typedef struct PatternInfoArray PatternInfoArray |
typedef struct RelationInfo RelationInfo |
|
static |
Definition at line 1511 of file pg_amcheck.c.
References append_relation_pattern_helper(), and encoding.
Referenced by main().
|
static |
Definition at line 1357 of file pg_amcheck.c.
References buf, PatternInfo::db_regex, encoding, exit(), extend_pattern_info_array(), initPQExpBuffer(), PatternInfo::pattern, patternToSQLRegex(), pg_log_error, pstrdup(), and termPQExpBuffer().
Referenced by main().
|
static |
Definition at line 1538 of file pg_amcheck.c.
References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), appendStringLiteralConn(), buf, comma, conn, PatternInfoArray::data, PatternInfo::db_regex, PatternInfoArray::len, PatternInfo::nsp_regex, and PatternInfo::rel_regex.
Referenced by compile_database_list().
|
static |
Definition at line 1495 of file pg_amcheck.c.
References append_relation_pattern_helper(), and encoding.
Referenced by main().
|
static |
Definition at line 1845 of file pg_amcheck.c.
References appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralConn(), buf, conn, and PQdb().
Referenced by compile_relation_list_one_db().
|
static |
Definition at line 1776 of file pg_amcheck.c.
References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), appendStringLiteralConn(), PatternInfo::btree_only, buf, comma, conn, PatternInfoArray::data, PatternInfo::db_regex, PatternInfo::heap_only, PatternInfoArray::len, PatternInfo::nsp_regex, and PatternInfo::rel_regex.
Referenced by compile_relation_list_one_db().
|
static |
Definition at line 1479 of file pg_amcheck.c.
References append_relation_pattern_helper(), and encoding.
Referenced by main().
|
static |
Definition at line 1429 of file pg_amcheck.c.
References PatternInfo::btree_only, PQExpBufferData::data, PatternInfo::db_regex, AmcheckOptions::dbpattern, encoding, exit(), extend_pattern_info_array(), PatternInfo::heap_only, initPQExpBuffer(), PatternInfo::nsp_regex, opts, PatternInfo::pattern, patternToSQLRegex(), pg_log_error, pstrdup(), PatternInfo::rel_regex, and termPQExpBuffer().
Referenced by append_btree_pattern(), append_heap_pattern(), and append_relation_pattern().
|
static |
Definition at line 1387 of file pg_amcheck.c.
References PQExpBufferData::data, PatternInfo::db_regex, AmcheckOptions::dbpattern, encoding, exit(), extend_pattern_info_array(), initPQExpBuffer(), PatternInfo::nsp_regex, opts, PatternInfo::pattern, patternToSQLRegex(), pg_log_error, pstrdup(), and termPQExpBuffer().
Referenced by main().
|
static |
Definition at line 1584 of file pg_amcheck.c.
References AmcheckOptions::alldb, append_db_pattern_cte(), appendPQExpBufferStr(), Assert, conn, PatternInfoArray::data, PQExpBufferData::data, DatabaseInfo::datname, datname, disconnectDatabase(), AmcheckOptions::echo, AmcheckOptions::exclude, executeQuery(), exit(), i, AmcheckOptions::include, initPQExpBuffer(), PatternInfoArray::len, log_no_match, opts, PatternInfo::pattern, pg_fatal, pg_log_error, pg_log_error_detail, pg_log_info, pg_malloc0(), PGRES_TUPLES_OK, PQclear(), PQerrorMessage(), PQgetisnull(), PQgetvalue(), PQntuples(), PQresultStatus(), pstrdup(), res, simple_ptr_list_append(), AmcheckOptions::strict_names, termPQExpBuffer(), and AmcheckOptions::verbose.
Referenced by main().
|
static |
Definition at line 1884 of file pg_amcheck.c.
References AmcheckOptions::allrel, append_rel_pattern_filtered_cte(), append_rel_pattern_raw_cte(), appendPQExpBuffer(), appendPQExpBufferStr(), Assert, atooid, RelationInfo::blocks_to_check, conn, CppAsString2, PatternInfoArray::data, PQExpBufferData::data, RelationInfo::datinfo, disconnectDatabase(), AmcheckOptions::echo, AmcheckOptions::endblock, AmcheckOptions::exclude, AmcheckOptions::excludeidx, AmcheckOptions::excludensp, AmcheckOptions::excludetbl, executeQuery(), exit(), i, AmcheckOptions::include, initPQExpBuffer(), InvalidOid, RelationInfo::is_heap, PatternInfoArray::len, PatternInfo::matched, AmcheckOptions::no_btree_expansion, AmcheckOptions::no_toast_expansion, RelationInfo::nspname, OidIsValid, opts, pg_fatal, pg_log_error, pg_log_error_detail, pg_malloc0(), PG_USED_FOR_ASSERTS_ONLY, PGRES_TUPLES_OK, PQclear(), PQerrorMessage(), PQgetisnull(), PQgetvalue(), PQntuples(), PQresultStatus(), pstrdup(), RelationInfo::relname, relname, RelationInfo::reloid, RelationInfo::relpages, res, simple_ptr_list_append(), AmcheckOptions::startblock, and termPQExpBuffer().
Referenced by main().
|
static |
Definition at line 1335 of file pg_amcheck.c.
References PatternInfoArray::data, PatternInfoArray::len, and pg_realloc().
Referenced by append_database_pattern(), append_relation_pattern_helper(), and append_schema_pattern().
|
static |
|
static |
Definition at line 1007 of file pg_amcheck.c.
References appendPQExpBufferChar(), appendPQExpBufferStr(), buf, initPQExpBuffer(), pstrdup(), str, and termPQExpBuffer().
Referenced by verify_btree_slot_handler(), and verify_heap_slot_handler().
int main | ( | int | argc, |
char * | argv[] | ||
) |
Definition at line 220 of file pg_amcheck.c.
References all_checks_pass, AmcheckOptions::alldb, AmcheckOptions::allrel, DatabaseInfo::amcheck_schema, amcheck_sql, append_btree_pattern(), append_database_pattern(), append_heap_pattern(), append_relation_pattern(), append_schema_pattern(), RelationInfo::blocks_to_check, PatternInfo::btree_only, CancelRequested, AmcheckOptions::checkunique, compile_database_list(), compile_relation_list_one_db(), conn, connectDatabase(), ParallelSlot::connection, connectMaintenanceDatabase(), PatternInfoArray::data, PQExpBufferData::data, RelationInfo::datinfo, DatabaseInfo::datname, _connParams::dbname, AmcheckOptions::dbpattern, disconnectDatabase(), AmcheckOptions::echo, encoding, AmcheckOptions::endblock, AmcheckOptions::exclude, AmcheckOptions::excludeidx, AmcheckOptions::excludensp, AmcheckOptions::excludetbl, executeCommand(), executeQuery(), exit(), fprintf, FREE_AND_SET_NULL, get_progname(), get_user_name_or_exit(), getopt_long(), handle_help_version_opts(), SimplePtrList::head, PatternInfo::heap_only, AmcheckOptions::heapallindexed, help(), if(), AmcheckOptions::include, initPQExpBuffer(), AmcheckOptions::install_missing, AmcheckOptions::install_schema, DatabaseInfo::is_checkunique, RelationInfo::is_heap, AmcheckOptions::jobs, PatternInfoArray::len, log_no_match, PatternInfo::matched, MaxBlockNumber, SimplePtrListCell::next, no_argument, AmcheckOptions::no_btree_expansion, AmcheckOptions::no_toast_expansion, PatternInfo::nsp_regex, RelationInfo::nspname, AmcheckOptions::on_error_stop, optarg, optind, option_parse_int(), optional_argument, opts, _connParams::override_dbname, ParallelSlotsAdoptConn(), ParallelSlotSetHandler(), ParallelSlotsGetIdle(), ParallelSlotsSetup(), ParallelSlotsTerminate(), ParallelSlotsWaitCompletion(), AmcheckOptions::parent_check, PatternInfo::pattern, pfree(), pg_fatal, pg_get_encoding_from_locale(), pg_log_error, pg_log_error_detail, pg_log_error_hint, pg_log_info, pg_log_warning, pg_logging_increase_verbosity(), pg_logging_init(), pg_strcasecmp(), pg_strdup(), PG_TEXTDOMAIN, _connParams::pghost, _connParams::pgport, PGRES_TUPLES_OK, _connParams::pguser, port, PQclear(), PQdb(), PQerrorMessage(), PQERRORS_VERBOSE, PQescapeIdentifier(), PQgetvalue(), PQntuples(), PQresultStatus(), PQsetErrorVerbosity(), prepare_btree_command(), prepare_heap_command(), progname, progress_report(), progress_since_last_stderr, _connParams::prompt_password, psprintf(), pstrdup(), SimplePtrListCell::ptr, AmcheckOptions::reconcile_toast, PatternInfo::rel_regex, RelationInfo::relname, required_argument, AmcheckOptions::rootdescend, run_command(), set_pglocale_pgservice(), setup_cancel_handler(), AmcheckOptions::show_progress, AmcheckOptions::skip, RelationInfo::sql, AmcheckOptions::startblock, AmcheckOptions::strict_names, termPQExpBuffer(), TRI_DEFAULT, TRI_NO, TRI_YES, username, AmcheckOptions::verbose, verify_btree_slot_handler(), and verify_heap_slot_handler().
|
static |
Definition at line 882 of file pg_amcheck.c.
References DatabaseInfo::amcheck_schema, appendPQExpBuffer(), CppAsString2, RelationInfo::datinfo, AmcheckOptions::heapallindexed, DatabaseInfo::is_checkunique, opts, AmcheckOptions::parent_check, RelationInfo::reloid, resetPQExpBuffer(), and AmcheckOptions::rootdescend.
Referenced by main().
|
static |
Definition at line 842 of file pg_amcheck.c.
References DatabaseInfo::amcheck_schema, appendPQExpBuffer(), CppAsString2, RelationInfo::datinfo, AmcheckOptions::endblock, INT64_FORMAT, AmcheckOptions::on_error_stop, opts, AmcheckOptions::reconcile_toast, RelationInfo::reloid, resetPQExpBuffer(), AmcheckOptions::skip, and AmcheckOptions::startblock.
Referenced by main().
|
static |
Definition at line 1243 of file pg_amcheck.c.
References _, datname, fprintf, last_progress_report, now(), opts, progress_since_last_stderr, AmcheckOptions::show_progress, snprintf, UINT64_FORMAT, AmcheckOptions::verbose, and VERBOSE_DATNAME_LENGTH.
Referenced by main(), and write_target_range().
|
static |
Definition at line 931 of file pg_amcheck.c.
References ParallelSlot::connection, AmcheckOptions::echo, exit(), opts, pg_log_error, pg_log_error_detail, PQdb(), PQerrorMessage(), PQsendQuery(), and printf.
Referenced by main().
|
static |
Definition at line 963 of file pg_amcheck.c.
References PG_DIAG_SEVERITY_NONLOCALIZED, PGRES_BAD_RESPONSE, PGRES_COMMAND_OK, PGRES_COPY_BOTH, PGRES_COPY_IN, PGRES_COPY_OUT, PGRES_EMPTY_QUERY, PGRES_FATAL_ERROR, PGRES_NONFATAL_ERROR, PGRES_PIPELINE_ABORTED, PGRES_PIPELINE_SYNC, PGRES_SINGLE_TUPLE, PGRES_TUPLES_CHUNK, PGRES_TUPLES_OK, PQresultErrorField(), PQresultStatus(), and res.
Referenced by verify_btree_slot_handler(), and verify_heap_slot_handler().
Definition at line 1119 of file pg_amcheck.c.
References _, all_checks_pass, conn, RelationInfo::datinfo, DatabaseInfo::datname, fprintf, FREE_AND_SET_NULL, indent_lines(), RelationInfo::nspname, opts, pg_log_warning, pg_log_warning_detail, pg_log_warning_hint, PGRES_TUPLES_OK, PQerrorMessage(), PQntuples(), PQresultStatus(), printf, progname, progress_since_last_stderr, RelationInfo::relname, res, should_processing_continue(), AmcheckOptions::show_progress, RelationInfo::sql, and AmcheckOptions::verbose.
Referenced by main().
Definition at line 1038 of file pg_amcheck.c.
References _, all_checks_pass, conn, RelationInfo::datinfo, DatabaseInfo::datname, FREE_AND_SET_NULL, i, indent_lines(), RelationInfo::nspname, opts, PGRES_TUPLES_OK, PQerrorMessage(), PQgetisnull(), PQgetvalue(), PQntuples(), PQresultStatus(), printf, RelationInfo::relname, res, should_processing_continue(), RelationInfo::sql, and AmcheckOptions::verbose.
Referenced by main().
|
static |
Definition at line 144 of file pg_amcheck.c.
Referenced by main(), verify_btree_slot_handler(), and verify_heap_slot_handler().
|
static |
Definition at line 173 of file pg_amcheck.c.
Referenced by main().
|
static |
Definition at line 147 of file pg_amcheck.c.
Referenced by progress_report().
|
static |
Definition at line 112 of file pg_amcheck.c.
Referenced by AlterSubscription(), append_relation_pattern_helper(), append_schema_pattern(), ArchiveEntry(), BloomFillMetapage(), brin_bloom_add_value(), brin_bloom_get_ndistinct(), brin_minmax_multi_add_value(), brin_minmax_multi_get_values(), build_local_reloptions(), compile_database_list(), compile_relation_list_one_db(), copy_connection(), CopyIndexAttOptions(), CreateSubscription(), get_attribute_options(), get_tablespace(), getFormattedTypeName(), initBloomState(), InitDumpOptions(), libpqrcv_check_conninfo(), libpqrcv_get_dbname_from_conninfo(), main(), makeDefaultBloomOptions(), NewDumpOptions(), NewRestoreOptions(), parse_re_flags(), parse_subscription_options(), parse_test_flags(), prepare_btree_command(), prepare_heap_command(), progress_report(), read_restore_filters(), RelationGetIndexAttOptions(), run_command(), sql_exec_dumpalldbs(), sql_exec_dumpalltables(), sql_exec_dumpalltbspc(), sql_exec_searchtables(), verify_btree_slot_handler(), and verify_heap_slot_handler().
|
static |
Definition at line 141 of file pg_amcheck.c.
Referenced by help(), main(), and verify_btree_slot_handler().
|
static |
Definition at line 148 of file pg_amcheck.c.
Referenced by main(), progress_report(), and verify_btree_slot_handler().