1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-15 05:46:52 +03:00

Split vacuumdb to create vacuuming.c/h

This allows these routines to be reused by a future utility heavily
based on vacuumdb.

I made a few relatively minor changes from the original, most notably:

- objfilter was declared as an enum but the values are bit-or'ed, and
  individual bits are tested throughout the code.  We've discussed this
  coding pattern in other contexts and stayed away from it, on the
  grounds that the values so generated aren't really true values of the
  enum.  This commit changes it to be a bits32 with a few #defines for
  the flag definitions, the way we do elsewhere.  Also, instead of being
  a global variable, it's now in the vacuumingOptions struct.

- Two booleans, analyze_only (in vacuumingOptions) and analyze_in_stages
  (passed around as a separate boolean argument), are really determining
  what "mode" the program runs in -- it's either vacuum, or one of those
  two modes.  I have three adjectives for them: inconsistent,
  unergonomic, unorthodox.  Removing these and replacing them with a
  mode enum to be kept in vacuumingOptions makes the code structure easier
  to understand in a couple of places, and it'll be useful for the new
  mode we add next, so do that.

Reviewed-by: Antonin Houska <ah@cybertec.at>
Discussion: https://postgr.es/m/202508301750.cbohxyy2pcce@alvherre.pgsql
This commit is contained in:
Álvaro Herrera
2025-09-26 16:21:28 +02:00
parent dbf8cfb4f0
commit c4067383cb
7 changed files with 1146 additions and 1049 deletions

View File

@@ -28,7 +28,7 @@ createuser: createuser.o common.o $(WIN32RES) | submake-libpq submake-libpgport
dropdb: dropdb.o common.o $(WIN32RES) | submake-libpq submake-libpgport submake-libpgfeutils
dropuser: dropuser.o common.o $(WIN32RES) | submake-libpq submake-libpgport submake-libpgfeutils
clusterdb: clusterdb.o common.o $(WIN32RES) | submake-libpq submake-libpgport submake-libpgfeutils
vacuumdb: vacuumdb.o common.o $(WIN32RES) | submake-libpq submake-libpgport submake-libpgfeutils
vacuumdb: vacuumdb.o vacuuming.o common.o $(WIN32RES) | submake-libpq submake-libpgport submake-libpgfeutils
reindexdb: reindexdb.o common.o $(WIN32RES) | submake-libpq submake-libpgport submake-libpgfeutils
pg_isready: pg_isready.o common.o $(WIN32RES) | submake-libpq submake-libpgport submake-libpgfeutils
@@ -50,7 +50,7 @@ uninstall:
clean distclean:
rm -f $(addsuffix $(X), $(PROGRAMS)) $(addsuffix .o, $(PROGRAMS))
rm -f common.o $(WIN32RES)
rm -f common.o vacuuming.o $(WIN32RES)
rm -rf tmp_check
export with_icu

View File

@@ -12,7 +12,6 @@ binaries = [
'createuser',
'dropuser',
'clusterdb',
'vacuumdb',
'reindexdb',
'pg_isready',
]
@@ -35,6 +34,33 @@ foreach binary : binaries
bin_targets += binary
endforeach
vacuuming_common = static_library('libvacuuming_common',
files('common.c', 'vacuuming.c'),
dependencies: [frontend_code, libpq],
kwargs: internal_lib_args,
)
binaries = [
'vacuumdb',
]
foreach binary : binaries
binary_sources = files('@0@.c'.format(binary))
if host_system == 'windows'
binary_sources += rc_bin_gen.process(win32ver_rc, extra_args: [
'--NAME', binary,
'--FILEDESC', '@0@ - PostgreSQL utility'.format(binary),])
endif
binary = executable(binary,
binary_sources,
link_with: [vacuuming_common],
dependencies: [frontend_code, libpq],
kwargs: default_bin_args,
)
bin_targets += binary
endforeach
tests += {
'name': 'scripts',
'sd': meson.current_source_dir(),

View File

@@ -7,6 +7,7 @@ GETTEXT_FILES = $(FRONTEND_COMMON_GETTEXT_FILES) \
dropuser.c \
clusterdb.c \
vacuumdb.c \
vacuuming.c \
reindexdb.c \
pg_isready.c \
common.c \

File diff suppressed because it is too large Load Diff

1004
src/bin/scripts/vacuuming.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,72 @@
/*-------------------------------------------------------------------------
*
* vacuuming.h
* Common declarations for vacuuming.c
*
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/bin/scripts/vacuuming.h
*
*-------------------------------------------------------------------------
*/
#ifndef VACUUMING_H
#define VACUUMING_H
#include "common.h"
#include "fe_utils/connect_utils.h"
#include "fe_utils/simple_list.h"
typedef enum
{
MODE_VACUUM,
MODE_ANALYZE,
MODE_ANALYZE_IN_STAGES
} RunMode;
/* For analyze-in-stages mode */
#define ANALYZE_NO_STAGE -1
#define ANALYZE_NUM_STAGES 3
/* vacuum options controlled by user flags */
typedef struct vacuumingOptions
{
RunMode mode;
bits32 objfilter;
bool verbose;
bool and_analyze;
bool full;
bool freeze;
bool disable_page_skipping;
bool skip_locked;
int min_xid_age;
int min_mxid_age;
int parallel_workers; /* >= 0 indicates user specified the
* parallel degree, otherwise -1 */
bool no_index_cleanup;
bool force_index_cleanup;
bool do_truncate;
bool process_main;
bool process_toast;
bool skip_database_stats;
char *buffer_usage_limit;
bool missing_stats_only;
} vacuumingOptions;
/* Valid values for vacuumingOptions->objfilter */
#define OBJFILTER_ALL_DBS 0x01 /* --all */
#define OBJFILTER_DATABASE 0x02 /* --dbname */
#define OBJFILTER_TABLE 0x04 /* --table */
#define OBJFILTER_SCHEMA 0x08 /* --schema */
#define OBJFILTER_SCHEMA_EXCLUDE 0x10 /* --exclude-schema */
extern int vacuuming_main(ConnParams *cparams, const char *dbname,
const char *maintenance_db, vacuumingOptions *vacopts,
SimpleStringList *objects,
unsigned int tbl_count,
int concurrentCons,
const char *progname, bool echo, bool quiet);
extern char *escape_quotes(const char *src);
#endif /* VACUUMING_H */

View File

@@ -2604,6 +2604,7 @@ RtlNtStatusToDosError_t
RuleInfo
RuleLock
RuleStmt
RunMode
RunningTransactions
RunningTransactionsData
SASLStatus