resolve conflicts
This commit is contained in:
commit
e1f362e831
4
Makefile
4
Makefile
@ -24,8 +24,8 @@ INTVERSION := $(shell echo $$(($$(echo $(VERSION) | sed 's/\([[:digit:]]\{1,\}\)
|
|||||||
EXTVERSION = $(shell grep '"version":' META.json | head -1 \
|
EXTVERSION = $(shell grep '"version":' META.json | head -1 \
|
||||||
| sed -e 's/[ ]*"version":[ ]*"\(.*\)",/\1/')
|
| sed -e 's/[ ]*"version":[ ]*"\(.*\)",/\1/')
|
||||||
|
|
||||||
ifeq ($(shell echo $$(($(INTVERSION) < 803))),1)
|
ifeq ($(shell echo $$(($(INTVERSION) < 901))),1)
|
||||||
$(error $(EXTENSION) requires PostgreSQL 8.3 or later. This is $(VERSION))
|
$(error $(EXTENSION) requires PostgreSQL 9.1 or later. This is $(VERSION))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
SUBDIRS = bin lib regress
|
SUBDIRS = bin lib regress
|
||||||
|
@ -23,10 +23,6 @@ CLUSTER directly.
|
|||||||
Please check the documentation (in the ``doc`` directory or online_) for
|
Please check the documentation (in the ``doc`` directory or online_) for
|
||||||
installation and usage instructions.
|
installation and usage instructions.
|
||||||
|
|
||||||
All users of pg_reorg 1.1.9 or earlier, and pg_repack 1.2.0-beta1 or earlier,
|
|
||||||
are **urged to upgrade** to the latest pg_repack version to fix a serious
|
|
||||||
data corruption issue_.
|
|
||||||
|
|
||||||
.. _pg_repack: http://reorg.github.com/pg_repack
|
.. _pg_repack: http://reorg.github.com/pg_repack
|
||||||
.. _CLUSTER: http://www.postgresql.org/docs/current/static/sql-cluster.html
|
.. _CLUSTER: http://www.postgresql.org/docs/current/static/sql-cluster.html
|
||||||
.. _VACUUM FULL: VACUUM_
|
.. _VACUUM FULL: VACUUM_
|
||||||
|
@ -26,7 +26,6 @@ endif
|
|||||||
PG_LIBS = $(libpq)
|
PG_LIBS = $(libpq)
|
||||||
|
|
||||||
USE_PGXS = 1 # use pgxs if not in contrib directory
|
USE_PGXS = 1 # use pgxs if not in contrib directory
|
||||||
PG_CONFIG = pg_config
|
|
||||||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||||
include $(PGXS)
|
include $(PGXS)
|
||||||
|
|
||||||
|
@ -193,7 +193,9 @@ typedef struct repack_table
|
|||||||
const char *create_log; /* CREATE TABLE log */
|
const char *create_log; /* CREATE TABLE log */
|
||||||
const char *create_trigger; /* CREATE TRIGGER repack_trigger */
|
const char *create_trigger; /* CREATE TRIGGER repack_trigger */
|
||||||
const char *enable_trigger; /* ALTER TABLE ENABLE ALWAYS TRIGGER repack_trigger */
|
const char *enable_trigger; /* ALTER TABLE ENABLE ALWAYS TRIGGER repack_trigger */
|
||||||
const char *create_table; /* CREATE TABLE table AS SELECT */
|
const char *create_table; /* CREATE TABLE table AS SELECT WITH NO DATA*/
|
||||||
|
const char *copy_data; /* INSERT INTO */
|
||||||
|
const char *alter_col_storage; /* ALTER TABLE ALTER COLUMN SET STORAGE */
|
||||||
const char *drop_columns; /* ALTER TABLE DROP COLUMNs */
|
const char *drop_columns; /* ALTER TABLE DROP COLUMNs */
|
||||||
const char *delete_log; /* DELETE FROM log */
|
const char *delete_log; /* DELETE FROM log */
|
||||||
const char *lock_table; /* LOCK TABLE table */
|
const char *lock_table; /* LOCK TABLE table */
|
||||||
@ -799,6 +801,8 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
|
|||||||
create_table_1 = getstr(res, i, c++);
|
create_table_1 = getstr(res, i, c++);
|
||||||
tablespace = getstr(res, i, c++); /* to be clobbered */
|
tablespace = getstr(res, i, c++); /* to be clobbered */
|
||||||
create_table_2 = getstr(res, i, c++);
|
create_table_2 = getstr(res, i, c++);
|
||||||
|
table.copy_data = getstr(res, i , c++);
|
||||||
|
table.alter_col_storage = getstr(res, i, c++);
|
||||||
table.drop_columns = getstr(res, i, c++);
|
table.drop_columns = getstr(res, i, c++);
|
||||||
table.delete_log = getstr(res, i, c++);
|
table.delete_log = getstr(res, i, c++);
|
||||||
table.lock_table = getstr(res, i, c++);
|
table.lock_table = getstr(res, i, c++);
|
||||||
@ -821,27 +825,25 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
|
|||||||
/* CLUSTER mode */
|
/* CLUSTER mode */
|
||||||
appendStringInfoString(&sql, " ORDER BY ");
|
appendStringInfoString(&sql, " ORDER BY ");
|
||||||
appendStringInfoString(&sql, ckey);
|
appendStringInfoString(&sql, ckey);
|
||||||
table.create_table = sql.data;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* VACUUM FULL mode (non-clustered tables) */
|
|
||||||
table.create_table = sql.data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* else, VACUUM FULL mode (non-clustered tables) */
|
||||||
}
|
}
|
||||||
else if (!orderby[0])
|
else if (!orderby[0])
|
||||||
{
|
{
|
||||||
/* VACUUM FULL mode (for clustered tables too) */
|
/* VACUUM FULL mode (for clustered tables too), do nothing */
|
||||||
table.create_table = sql.data;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* User specified ORDER BY */
|
/* User specified ORDER BY */
|
||||||
appendStringInfoString(&sql, " ORDER BY ");
|
appendStringInfoString(&sql, " ORDER BY ");
|
||||||
appendStringInfoString(&sql, orderby);
|
appendStringInfoString(&sql, orderby);
|
||||||
table.create_table = sql.data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Always append WITH NOT DATA */
|
||||||
|
appendStringInfoString(&sql, " WITH NO DATA");
|
||||||
|
table.create_table = sql.data;
|
||||||
|
|
||||||
repack_one_table(&table, orderby);
|
repack_one_table(&table, orderby);
|
||||||
}
|
}
|
||||||
ret = true;
|
ret = true;
|
||||||
@ -1126,25 +1128,28 @@ repack_one_table(repack_table *table, const char *orderby)
|
|||||||
elog(INFO, "repacking table \"%s\"", table->target_name);
|
elog(INFO, "repacking table \"%s\"", table->target_name);
|
||||||
|
|
||||||
elog(DEBUG2, "---- repack_one_table ----");
|
elog(DEBUG2, "---- repack_one_table ----");
|
||||||
elog(DEBUG2, "target_name : %s", table->target_name);
|
elog(DEBUG2, "target_name : %s", table->target_name);
|
||||||
elog(DEBUG2, "target_oid : %u", table->target_oid);
|
elog(DEBUG2, "target_oid : %u", table->target_oid);
|
||||||
elog(DEBUG2, "target_toast : %u", table->target_toast);
|
elog(DEBUG2, "target_toast : %u", table->target_toast);
|
||||||
elog(DEBUG2, "target_tidx : %u", table->target_tidx);
|
elog(DEBUG2, "target_tidx : %u", table->target_tidx);
|
||||||
elog(DEBUG2, "pkid : %u", table->pkid);
|
elog(DEBUG2, "pkid : %u", table->pkid);
|
||||||
elog(DEBUG2, "ckid : %u", table->ckid);
|
elog(DEBUG2, "ckid : %u", table->ckid);
|
||||||
elog(DEBUG2, "create_pktype : %s", table->create_pktype);
|
elog(DEBUG2, "create_pktype : %s", table->create_pktype);
|
||||||
elog(DEBUG2, "create_log : %s", table->create_log);
|
elog(DEBUG2, "create_log : %s", table->create_log);
|
||||||
elog(DEBUG2, "create_trigger : %s", table->create_trigger);
|
elog(DEBUG2, "create_trigger : %s", table->create_trigger);
|
||||||
elog(DEBUG2, "enable_trigger : %s", table->enable_trigger);
|
elog(DEBUG2, "enable_trigger : %s", table->enable_trigger);
|
||||||
elog(DEBUG2, "create_table : %s", table->create_table);
|
elog(DEBUG2, "create_table : %s", table->create_table);
|
||||||
elog(DEBUG2, "drop_columns : %s", table->drop_columns ? table->drop_columns : "(skipped)");
|
elog(DEBUG2, "copy_data : %s", table->copy_data);
|
||||||
elog(DEBUG2, "delete_log : %s", table->delete_log);
|
elog(DEBUG2, "alter_col_storage : %s", table->alter_col_storage ?
|
||||||
elog(DEBUG2, "lock_table : %s", table->lock_table);
|
table->alter_col_storage : "(skipped)");
|
||||||
elog(DEBUG2, "sql_peek : %s", table->sql_peek);
|
elog(DEBUG2, "drop_columns : %s", table->drop_columns ? table->drop_columns : "(skipped)");
|
||||||
elog(DEBUG2, "sql_insert : %s", table->sql_insert);
|
elog(DEBUG2, "delete_log : %s", table->delete_log);
|
||||||
elog(DEBUG2, "sql_delete : %s", table->sql_delete);
|
elog(DEBUG2, "lock_table : %s", table->lock_table);
|
||||||
elog(DEBUG2, "sql_update : %s", table->sql_update);
|
elog(DEBUG2, "sql_peek : %s", table->sql_peek);
|
||||||
elog(DEBUG2, "sql_pop : %s", table->sql_pop);
|
elog(DEBUG2, "sql_insert : %s", table->sql_insert);
|
||||||
|
elog(DEBUG2, "sql_delete : %s", table->sql_delete);
|
||||||
|
elog(DEBUG2, "sql_update : %s", table->sql_update);
|
||||||
|
elog(DEBUG2, "sql_pop : %s", table->sql_pop);
|
||||||
|
|
||||||
if (dryrun)
|
if (dryrun)
|
||||||
return;
|
return;
|
||||||
@ -1386,7 +1391,14 @@ repack_one_table(repack_table *table, const char *orderby)
|
|||||||
if (!(lock_access_share(connection, table->target_oid, table->target_name)))
|
if (!(lock_access_share(connection, table->target_oid, table->target_name)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Before copying data to the target table, we need to set the column storage
|
||||||
|
* type if its storage type has been changed from the type default.
|
||||||
|
*/
|
||||||
command(table->create_table, 0, NULL);
|
command(table->create_table, 0, NULL);
|
||||||
|
if (table->alter_col_storage)
|
||||||
|
command(table->alter_col_storage, 0, NULL);
|
||||||
|
command(table->copy_data, 0, NULL);
|
||||||
temp_obj_num++;
|
temp_obj_num++;
|
||||||
printfStringInfo(&sql, "SELECT repack.disable_autovacuum('repack.table_%u')", table->target_oid);
|
printfStringInfo(&sql, "SELECT repack.disable_autovacuum('repack.table_%u')", table->target_oid);
|
||||||
if (table->drop_columns)
|
if (table->drop_columns)
|
||||||
|
@ -79,11 +79,9 @@ pgut_init(int argc, char **argv)
|
|||||||
pthread_mutex_init(&pgut_conn_mutex, NULL);
|
pthread_mutex_init(&pgut_conn_mutex, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if PG_VERSION_NUM >= 90000
|
|
||||||
/* application_name for 9.0 or newer versions */
|
/* application_name for 9.0 or newer versions */
|
||||||
if (getenv("PGAPPNAME") == NULL)
|
if (getenv("PGAPPNAME") == NULL)
|
||||||
pgut_putenv("PGAPPNAME", PROGRAM_NAME);
|
pgut_putenv("PGAPPNAME", PROGRAM_NAME);
|
||||||
#endif
|
|
||||||
|
|
||||||
init_cancel_handler();
|
init_cancel_handler();
|
||||||
atexit(on_cleanup);
|
atexit(on_cleanup);
|
||||||
|
@ -24,6 +24,10 @@
|
|||||||
|
|
||||||
#define INFINITE_STR "INFINITE"
|
#define INFINITE_STR "INFINITE"
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define __attribute__(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef enum YesNo
|
typedef enum YesNo
|
||||||
{
|
{
|
||||||
DEFAULT,
|
DEFAULT,
|
||||||
@ -195,25 +199,6 @@ extern size_t simple_string_list_size(SimpleStringList list);
|
|||||||
extern int wait_for_socket(int sock, struct timeval *timeout);
|
extern int wait_for_socket(int sock, struct timeval *timeout);
|
||||||
extern int wait_for_sockets(int nfds, fd_set *fds, struct timeval *timeout);
|
extern int wait_for_sockets(int nfds, fd_set *fds, struct timeval *timeout);
|
||||||
|
|
||||||
/*
|
|
||||||
* import from postgres.h and catalog/genbki.h in 8.4
|
|
||||||
*/
|
|
||||||
#if PG_VERSION_NUM < 80400
|
|
||||||
|
|
||||||
typedef unsigned long Datum;
|
|
||||||
typedef struct MemoryContextData *MemoryContext;
|
|
||||||
|
|
||||||
#define CATALOG(name,oid) typedef struct CppConcat(FormData_,name)
|
|
||||||
#define BKI_BOOTSTRAP
|
|
||||||
#define BKI_SHARED_RELATION
|
|
||||||
#define BKI_WITHOUT_OIDS
|
|
||||||
#define DATA(x) extern int no_such_variable
|
|
||||||
#define DESCR(x) extern int no_such_variable
|
|
||||||
#define SHDESCR(x) extern int no_such_variable
|
|
||||||
typedef int aclitem;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
extern int sleep(unsigned int seconds);
|
extern int sleep(unsigned int seconds);
|
||||||
extern int usleep(unsigned int usec);
|
extern int usleep(unsigned int usec);
|
||||||
|
@ -40,7 +40,7 @@ Requirements
|
|||||||
------------
|
------------
|
||||||
|
|
||||||
PostgreSQL versions
|
PostgreSQL versions
|
||||||
PostgreSQL 8.3, 8.4, 9.0, 9.1, 9.2, 9.3, 9.4, 9.5, 9.6
|
PostgreSQL 9.1, 9.2, 9.3, 9.4, 9.5, 9.6
|
||||||
|
|
||||||
Disks
|
Disks
|
||||||
Performing a full-table repack requires free disk space about twice as
|
Performing a full-table repack requires free disk space about twice as
|
||||||
@ -84,21 +84,12 @@ You can also use Microsoft Visual C++ 2010 to build the program on Windows.
|
|||||||
There are project files in the ``msvc`` folder.
|
There are project files in the ``msvc`` folder.
|
||||||
|
|
||||||
After installation, load the pg_repack extension in the database you want to
|
After installation, load the pg_repack extension in the database you want to
|
||||||
process. On PostgreSQL 9.1 and following pg_repack is packaged as an
|
process. pg_repack is packaged as an extension, so you can execute::
|
||||||
extension, so you can execute::
|
|
||||||
|
|
||||||
$ psql -c "CREATE EXTENSION pg_repack" -d your_database
|
$ psql -c "CREATE EXTENSION pg_repack" -d your_database
|
||||||
|
|
||||||
For previous PostgreSQL versions you should load the script
|
You can remove pg_repack using ``DROP EXTENSION pg_repack`` or just dropping
|
||||||
``$SHAREDIR/contrib/pg_repack.sql`` in the database to process; you can
|
the ``repack`` schema.
|
||||||
get ``$SHAREDIR`` using ``pg_config --sharedir``, e.g. ::
|
|
||||||
|
|
||||||
$ psql -f "$(pg_config --sharedir)/contrib/pg_repack.sql" -d your_database
|
|
||||||
|
|
||||||
You can remove pg_repack from a PostgreSQL 9.1 and following database using
|
|
||||||
``DROP EXTENSION pg_repack``. For previous Postgresql versions load the
|
|
||||||
``$SHAREDIR/contrib/uninstall_pg_repack.sql`` script or just drop the
|
|
||||||
``repack`` schema.
|
|
||||||
|
|
||||||
If you are upgrading from a previous version of pg_repack or pg_reorg, just
|
If you are upgrading from a previous version of pg_repack or pg_reorg, just
|
||||||
drop the old version from the database as explained above and install the new
|
drop the old version from the database as explained above and install the new
|
||||||
@ -477,12 +468,14 @@ Releases
|
|||||||
|
|
||||||
* pg_repack 1.4
|
* pg_repack 1.4
|
||||||
|
|
||||||
* added support for PostgreSQL 9.6
|
* added support for PostgreSQL 9.6, dropped support for versions before 9.1
|
||||||
* use ``AFTER`` trigger to solve concurrency problems with ``INSERT
|
* use ``AFTER`` trigger to solve concurrency problems with ``INSERT
|
||||||
CONFLICT`` (issue #106)
|
CONFLICT`` (issue #106)
|
||||||
* added ``--no-kill-backend`` option (issue #108)
|
* added ``--no-kill-backend`` option (issue #108)
|
||||||
* added ``--no-superuser-check`` option (issue #114)
|
* added ``--no-superuser-check`` option (issue #114)
|
||||||
* added ``--exclude-extension`` option (#97)
|
* added ``--exclude-extension`` option (#97)
|
||||||
|
* restore TOAST storage parameters on repacked tables (issue #10)
|
||||||
|
* restore columns storage types in repacked tables (issue #94)
|
||||||
|
|
||||||
* pg_repack 1.3.4
|
* pg_repack 1.3.4
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ pg_repackでは再編成する方法として次のものが選択できます
|
|||||||
------------
|
------------
|
||||||
|
|
||||||
PostgreSQL versions
|
PostgreSQL versions
|
||||||
PostgreSQL 8.3, 8.4, 9.0, 9.1, 9.2, 9.3, 9.4, 9.5, 9.6
|
PostgreSQL 9.1, 9.2, 9.3, 9.4, 9.5, 9.6
|
||||||
|
|
||||||
Disks
|
Disks
|
||||||
Performing a full-table repack requires free disk space about twice as
|
Performing a full-table repack requires free disk space about twice as
|
||||||
@ -75,7 +75,7 @@ pg_repackでは再編成する方法として次のものが選択できます
|
|||||||
---------
|
---------
|
||||||
|
|
||||||
PostgreSQL バージョン
|
PostgreSQL バージョン
|
||||||
PostgreSQL 8.3, 8.4, 9.0, 9.1, 9.2, 9.3, 9.4
|
PostgreSQL 9.1, 9.2, 9.3, 9.4, 9.5, 9.6
|
||||||
|
|
||||||
ディスク
|
ディスク
|
||||||
テーブル全体の再編成を行うには、対象となるテーブルと付属するインデックスのおよそ2倍のサイズのディスク空き容量が必要です。例えば、テーブルとインデックスを合わせたサイズが1GBの場合、2GBのディスク領域が必要となります。
|
テーブル全体の再編成を行うには、対象となるテーブルと付属するインデックスのおよそ2倍のサイズのディスク空き容量が必要です。例えば、テーブルとインデックスを合わせたサイズが1GBの場合、2GBのディスク領域が必要となります。
|
||||||
@ -862,6 +862,8 @@ ACCESS EXCLUSIVEロックを取得します。その他のステップでは、A
|
|||||||
.. * added ``--no-kill-backend`` option (issue #108)
|
.. * added ``--no-kill-backend`` option (issue #108)
|
||||||
.. * added ``--no-superuser-check`` option (issue #114)
|
.. * added ``--no-superuser-check`` option (issue #114)
|
||||||
.. * added ``--exclude-extension`` option (#97)
|
.. * added ``--exclude-extension`` option (#97)
|
||||||
|
.. * restore TOAST storage parameters on repacked tables (issue #10)
|
||||||
|
.. * restore columns storage types in repacked tables (issue #94)
|
||||||
|
|
||||||
* pg_repack 1.4
|
* pg_repack 1.4
|
||||||
|
|
||||||
@ -871,6 +873,8 @@ ACCESS EXCLUSIVEロックを取得します。その他のステップでは、A
|
|||||||
* ``--no-kill-backend`` オプションを追加しました (issue #108)
|
* ``--no-kill-backend`` オプションを追加しました (issue #108)
|
||||||
* ``--no-superuser-check`` オプションを追加しました (issue #114)
|
* ``--no-superuser-check`` オプションを追加しました (issue #114)
|
||||||
* ``--exclude-extension`` オプションを追加しました (#97)
|
* ``--exclude-extension`` オプションを追加しました (#97)
|
||||||
|
* TOASTテーブルの格納オプションを再編成後のテーブルに再設定するようにしました (issue #10)
|
||||||
|
* 列の格納タイプを再編成後のテーブルに再設定するようにしました (issue #94)
|
||||||
|
|
||||||
.. * pg_repack 1.3.4
|
.. * pg_repack 1.3.4
|
||||||
.. * grab exclusive lock before dropping original table (#81)
|
.. * grab exclusive lock before dropping original table (#81)
|
||||||
|
@ -15,7 +15,7 @@ INTVERSION := $(shell echo $$(($$(echo $(VERSION) | sed 's/\([[:digit:]]\{1,\}\)
|
|||||||
EXTENSION = pg_repack
|
EXTENSION = pg_repack
|
||||||
MODULE_big = $(EXTENSION)
|
MODULE_big = $(EXTENSION)
|
||||||
|
|
||||||
OBJS = repack.o pgut/pgut-be.o pgut/pgut-spi.o
|
OBJS = repack.o pgut/pgut-spi.o
|
||||||
|
|
||||||
SHLIB_EXPORTS = exports.txt
|
SHLIB_EXPORTS = exports.txt
|
||||||
|
|
||||||
@ -25,13 +25,7 @@ REPACK_VERSION = $(shell grep '"version":' ../META.json | head -1 \
|
|||||||
|
|
||||||
PG_CPPFLAGS = -DREPACK_VERSION=$(REPACK_VERSION)
|
PG_CPPFLAGS = -DREPACK_VERSION=$(REPACK_VERSION)
|
||||||
|
|
||||||
# Support CREATE EXTENSION for PG >= 9.1 and a simple sql script for PG < 9.1
|
|
||||||
ifeq ($(shell echo $$(($(INTVERSION) >= 901))),1)
|
|
||||||
DATA_built = pg_repack--$(REPACK_VERSION).sql pg_repack.control
|
DATA_built = pg_repack--$(REPACK_VERSION).sql pg_repack.control
|
||||||
else
|
|
||||||
DATA_built = pg_repack.sql
|
|
||||||
DATA = uninstall_pg_repack.sql
|
|
||||||
endif
|
|
||||||
|
|
||||||
USE_PGXS = 1
|
USE_PGXS = 1
|
||||||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||||
|
@ -152,6 +152,72 @@ WHERE
|
|||||||
$$
|
$$
|
||||||
LANGUAGE sql STABLE STRICT;
|
LANGUAGE sql STABLE STRICT;
|
||||||
|
|
||||||
|
-- Get a comma-separated storage paramter for the table including
|
||||||
|
-- paramters for the corresponding TOAST table.
|
||||||
|
-- Note that since oid setting is always not NULL, this function
|
||||||
|
-- never returns NULL
|
||||||
|
CREATE FUNCTION repack.get_storage_param(oid)
|
||||||
|
RETURNS TEXT AS
|
||||||
|
$$
|
||||||
|
SELECT array_to_string(array_agg(param), ', ')
|
||||||
|
FROM (
|
||||||
|
-- table storage parameter
|
||||||
|
SELECT unnest(reloptions) as param
|
||||||
|
FROM pg_class
|
||||||
|
WHERE oid = $1
|
||||||
|
UNION ALL
|
||||||
|
-- TOAST table storage parameter
|
||||||
|
SELECT ('toast.' || unnest(reloptions)) as param
|
||||||
|
FROM (
|
||||||
|
SELECT reltoastrelid from pg_class where oid = $1
|
||||||
|
) as t,
|
||||||
|
pg_class as c
|
||||||
|
WHERE c.oid = t.reltoastrelid
|
||||||
|
UNION ALL
|
||||||
|
-- table oid
|
||||||
|
SELECT 'oids = ' ||
|
||||||
|
CASE WHEN relhasoids
|
||||||
|
THEN 'true'
|
||||||
|
ELSE 'false'
|
||||||
|
END
|
||||||
|
FROM pg_class
|
||||||
|
WHERE oid = $1
|
||||||
|
|
||||||
|
) as t
|
||||||
|
$$
|
||||||
|
LANGUAGE sql STABLE STRICT;
|
||||||
|
|
||||||
|
-- GET a SQL text to set column storage option for the table.
|
||||||
|
CREATE FUNCTION repack.get_alter_col_storage(oid)
|
||||||
|
RETURNS text AS
|
||||||
|
$$
|
||||||
|
SELECT 'ALTER TABLE repack.table_' || $1 || array_to_string(column_storage, ',')
|
||||||
|
FROM (
|
||||||
|
SELECT
|
||||||
|
repack.array_accum(' ALTER ' || quote_ident(attname) ||
|
||||||
|
CASE attstorage
|
||||||
|
WHEN 'p' THEN ' SET STORAGE PLAIN'
|
||||||
|
WHEN 'm' THEN ' SET STORAGE MAIN'
|
||||||
|
WHEN 'e' THEN ' SET STORAGE EXTERNAL'
|
||||||
|
WHEN 'x' THEN ' SET STORAGE EXTENDED'
|
||||||
|
END) AS column_storage
|
||||||
|
FROM (
|
||||||
|
SELECT *
|
||||||
|
FROM pg_attribute a
|
||||||
|
JOIN pg_type t on t.oid = atttypid
|
||||||
|
JOIN pg_class r on r.oid = a.attrelid
|
||||||
|
JOIN pg_namespace s on s.oid = r.relnamespace
|
||||||
|
WHERE typstorage <> attstorage
|
||||||
|
AND attrelid = $1
|
||||||
|
AND attnum > 0
|
||||||
|
AND NOT attisdropped
|
||||||
|
ORDER BY attnum
|
||||||
|
) T
|
||||||
|
) T
|
||||||
|
WHERE array_upper(column_storage , 1) > 0
|
||||||
|
$$
|
||||||
|
LANGUAGE sql STABLE STRICT;
|
||||||
|
|
||||||
-- includes not only PRIMARY KEYS but also UNIQUE NOT NULL keys
|
-- includes not only PRIMARY KEYS but also UNIQUE NOT NULL keys
|
||||||
CREATE VIEW repack.primary_keys AS
|
CREATE VIEW repack.primary_keys AS
|
||||||
SELECT indrelid, (repack.array_accum(indexrelid))[1] AS indexrelid
|
SELECT indrelid, (repack.array_accum(indexrelid))[1] AS indexrelid
|
||||||
@ -183,9 +249,11 @@ CREATE VIEW repack.tables AS
|
|||||||
'CREATE TABLE repack.log_' || R.oid || ' (id bigserial PRIMARY KEY, pk repack.pk_' || R.oid || ', row ' || repack.oid2text(R.oid) || ')' AS create_log,
|
'CREATE TABLE repack.log_' || R.oid || ' (id bigserial PRIMARY KEY, pk repack.pk_' || R.oid || ', row ' || repack.oid2text(R.oid) || ')' AS create_log,
|
||||||
repack.get_create_trigger(R.oid, PK.indexrelid) AS create_trigger,
|
repack.get_create_trigger(R.oid, PK.indexrelid) AS create_trigger,
|
||||||
repack.get_enable_trigger(R.oid) as enable_trigger,
|
repack.get_enable_trigger(R.oid) as enable_trigger,
|
||||||
'CREATE TABLE repack.table_' || R.oid || ' WITH (' || array_to_string(array_append(R.reloptions, 'oids=' || CASE WHEN R.relhasoids THEN 'true' ELSE 'false' END), ',') || ') TABLESPACE ' AS create_table_1,
|
'CREATE TABLE repack.table_' || R.oid || ' WITH (' || repack.get_storage_param(R.oid) || ') TABLESPACE ' AS create_table_1,
|
||||||
coalesce(quote_ident(S.spcname), 'pg_default') as tablespace_orig,
|
coalesce(quote_ident(S.spcname), 'pg_default') as tablespace_orig,
|
||||||
' AS SELECT ' || repack.get_columns_for_create_as(R.oid) || ' FROM ONLY ' || repack.oid2text(R.oid) AS create_table_2,
|
' AS SELECT ' || repack.get_columns_for_create_as(R.oid) || ' FROM ONLY ' || repack.oid2text(R.oid) AS create_table_2,
|
||||||
|
'INSERT INTO repack.table_' || R.oid || ' SELECT ' || repack.get_columns_for_create_as(R.oid) || ' FROM ONLY ' || repack.oid2text(R.oid) AS copy_data,
|
||||||
|
repack.get_alter_col_storage(R.oid) AS alter_col_storage,
|
||||||
repack.get_drop_columns(R.oid, 'repack.table_' || R.oid) AS drop_columns,
|
repack.get_drop_columns(R.oid, 'repack.table_' || R.oid) AS drop_columns,
|
||||||
'DELETE FROM repack.log_' || R.oid AS delete_log,
|
'DELETE FROM repack.log_' || R.oid AS delete_log,
|
||||||
'LOCK TABLE ' || repack.oid2text(R.oid) || ' IN ACCESS EXCLUSIVE MODE' AS lock_table,
|
'LOCK TABLE ' || repack.oid2text(R.oid) || ' IN ACCESS EXCLUSIVE MODE' AS lock_table,
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
/*-------------------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* pgut-be.c
|
|
||||||
*
|
|
||||||
* Copyright (c) 2009-2011, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
|
|
||||||
* Portions Copyright (c) 2012-2015, The Reorg Development Team
|
|
||||||
*
|
|
||||||
*-------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "postgres.h"
|
|
||||||
#include "access/heapam.h"
|
|
||||||
#include "pgut-be.h"
|
|
||||||
|
|
||||||
#if PG_VERSION_NUM < 80400
|
|
||||||
|
|
||||||
char *
|
|
||||||
text_to_cstring(const text *t)
|
|
||||||
{
|
|
||||||
text *tunpacked = pg_detoast_datum_packed((struct varlena *) t);
|
|
||||||
int len = VARSIZE_ANY_EXHDR(tunpacked);
|
|
||||||
char *result;
|
|
||||||
|
|
||||||
result = (char *) palloc(len + 1);
|
|
||||||
memcpy(result, VARDATA_ANY(tunpacked), len);
|
|
||||||
result[len] = '\0';
|
|
||||||
|
|
||||||
if (tunpacked != t)
|
|
||||||
pfree(tunpacked);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
text *
|
|
||||||
cstring_to_text(const char *s)
|
|
||||||
{
|
|
||||||
int len = strlen(s);
|
|
||||||
text *result = palloc(len + VARHDRSZ);
|
|
||||||
|
|
||||||
SET_VARSIZE(result, len + VARHDRSZ);
|
|
||||||
memcpy(VARDATA(result), s, len);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc,
|
|
||||||
Datum *values, bool *isnull)
|
|
||||||
{
|
|
||||||
tuplestore_puttuple(state, heap_form_tuple(tdesc, values, isnull));
|
|
||||||
}
|
|
||||||
|
|
||||||
Datum
|
|
||||||
ExecFetchSlotTupleDatum(TupleTableSlot *slot)
|
|
||||||
{
|
|
||||||
HeapTuple tup;
|
|
||||||
HeapTupleHeader td;
|
|
||||||
TupleDesc tupdesc;
|
|
||||||
|
|
||||||
/* Make sure we can scribble on the slot contents ... */
|
|
||||||
tup = ExecMaterializeSlot(slot);
|
|
||||||
/* ... and set up the composite-Datum header fields, in case not done */
|
|
||||||
td = tup->t_data;
|
|
||||||
tupdesc = slot->tts_tupleDescriptor;
|
|
||||||
HeapTupleHeaderSetDatumLength(td, tup->t_len);
|
|
||||||
HeapTupleHeaderSetTypeId(td, tupdesc->tdtypeid);
|
|
||||||
HeapTupleHeaderSetTypMod(td, tupdesc->tdtypmod);
|
|
||||||
return PointerGetDatum(td);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -52,116 +52,4 @@ extern int no_such_variable
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if PG_VERSION_NUM < 80400
|
|
||||||
|
|
||||||
#define MAIN_FORKNUM 0
|
|
||||||
#define HEAP_INSERT_SKIP_WAL 0x0001
|
|
||||||
#define HEAP_INSERT_SKIP_FSM 0x0002
|
|
||||||
|
|
||||||
#define relpath(rnode, forknum) relpath((rnode))
|
|
||||||
#define smgrimmedsync(reln, forknum) smgrimmedsync((reln))
|
|
||||||
#define smgrread(reln, forknum, blocknum, buffer) \
|
|
||||||
smgrread((reln), (blocknum), (buffer))
|
|
||||||
#define mdclose(reln, forknum) mdclose((reln))
|
|
||||||
#define heap_insert(relation, tup, cid, options, bistate) \
|
|
||||||
heap_insert((relation), (tup), (cid), true, true)
|
|
||||||
#define GetBulkInsertState() (NULL)
|
|
||||||
#define FreeBulkInsertState(bistate) ((void)0)
|
|
||||||
#define FreeExprContext(econtext, isCommit) FreeExprContext((econtext))
|
|
||||||
#define pgstat_init_function_usage(fcinfo, fcu) ((void)0)
|
|
||||||
#define pgstat_end_function_usage(fcu, finalize) ((void)0)
|
|
||||||
#define makeRangeVar(schemaname, relname, location) \
|
|
||||||
makeRangeVar((schemaname), (relname))
|
|
||||||
#define tuplestore_gettupleslot(state, forward, copy, slot) \
|
|
||||||
tuplestore_gettupleslot(state, forward, slot)
|
|
||||||
#define pgstat_track_activity_query_size PGBE_ACTIVITY_SIZE
|
|
||||||
typedef void *BulkInsertState;
|
|
||||||
|
|
||||||
#define DefineCustomBoolVariable(name, short_desc, long_desc, valueAddr, bootValue, context, flags, assign_hook, show_hook) \
|
|
||||||
do { \
|
|
||||||
*(valueAddr) = (bootValue); \
|
|
||||||
DefineCustomBoolVariable((name), (short_desc), (long_desc), (valueAddr), (context), (assign_hook), (show_hook)); \
|
|
||||||
} while(0)
|
|
||||||
#define DefineCustomIntVariable(name, short_desc, long_desc, valueAddr, bootValue, minValue, maxValue, context, flags, assign_hook, show_hook) \
|
|
||||||
do { \
|
|
||||||
*(valueAddr) = (bootValue); \
|
|
||||||
DefineCustomIntVariable((name), (short_desc), (long_desc), (valueAddr), (minValue), (maxValue), (context), (assign_hook), (show_hook)); \
|
|
||||||
} while(0)
|
|
||||||
#define DefineCustomRealVariable(name, short_desc, long_desc, valueAddr, bootValue, minValue, maxValue, context, flags, assign_hook, show_hook) \
|
|
||||||
do { \
|
|
||||||
*(valueAddr) = (bootValue); \
|
|
||||||
DefineCustomRealVariable((name), (short_desc), (long_desc), (valueAddr), (minValue), (maxValue), (context), (assign_hook), (show_hook)); \
|
|
||||||
} while(0)
|
|
||||||
#define DefineCustomStringVariable(name, short_desc, long_desc, valueAddr, bootValue, context, flags, assign_hook, show_hook) \
|
|
||||||
do { \
|
|
||||||
*(valueAddr) = (char *) (bootValue); \
|
|
||||||
DefineCustomStringVariable((name), (short_desc), (long_desc), (valueAddr), (context), (assign_hook), (show_hook)); \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
struct config_enum_entry
|
|
||||||
{
|
|
||||||
const char *name;
|
|
||||||
int val;
|
|
||||||
bool hidden;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern char *text_to_cstring(const text *t);
|
|
||||||
extern text *cstring_to_text(const char *s);
|
|
||||||
extern void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc,
|
|
||||||
Datum *values, bool *isnull);
|
|
||||||
extern Datum ExecFetchSlotTupleDatum(TupleTableSlot *slot);
|
|
||||||
|
|
||||||
#define CStringGetTextDatum(s) PointerGetDatum(cstring_to_text(s))
|
|
||||||
#define TextDatumGetCString(d) text_to_cstring((text *) DatumGetPointer(d))
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if PG_VERSION_NUM < 90000
|
|
||||||
|
|
||||||
#define reindex_index(indexId, skip_constraint_checks) \
|
|
||||||
reindex_index((indexId))
|
|
||||||
#define func_signature_string(funcname, nargs, argnames, argtypes) \
|
|
||||||
func_signature_string((funcname), (nargs), (argtypes))
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if PG_VERSION_NUM < 90200
|
|
||||||
|
|
||||||
#define RangeVarGetRelid(relation, lockmode, missing_ok, nowait) \
|
|
||||||
RangeVarGetRelid((relation), (missing_ok))
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if PG_VERSION_NUM < 90100
|
|
||||||
|
|
||||||
#define ATExecChangeOwner(relationOid, newOwnerId, recursing, lockmode) \
|
|
||||||
ATExecChangeOwner((relationOid), (newOwnerId), (recursing))
|
|
||||||
#define deleteDependencyRecordsFor(classId, objectId, skipExtensionDeps) \
|
|
||||||
deleteDependencyRecordsFor((classId), (objectId))
|
|
||||||
#define PG_GET_COLLATION() (InvalidOid)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if PG_VERSION_NUM < 90000
|
|
||||||
#define RelationSetNewRelfilenode(rel, xid) \
|
|
||||||
setNewRelfilenode((rel), (xid))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if PG_VERSION_NUM < 80400
|
|
||||||
#define FuncnameGetCandidates(names, nargs, argnames, variadic, defaults) \
|
|
||||||
FuncnameGetCandidates((names), (nargs))
|
|
||||||
#elif PG_VERSION_NUM < 90000
|
|
||||||
#define FuncnameGetCandidates(names, nargs, argnames, variadic, defaults) \
|
|
||||||
FuncnameGetCandidates((names), (nargs), (variadic), (defaults))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if PG_VERSION_NUM < 90000
|
|
||||||
#define GetConfigOption(name, missing_ok, restrict_superuser) \
|
|
||||||
GetConfigOption((name))
|
|
||||||
#elif PG_VERSION_NUM < 90200
|
|
||||||
#define GetConfigOption(name, missing_ok, restrict_superuser) \
|
|
||||||
GetConfigOption((name), (restrict_superuser))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* PGUT_BE_H */
|
#endif /* PGUT_BE_H */
|
||||||
|
@ -115,25 +115,3 @@ execute_with_format_args(int expected, const char *format, int nargs, Oid argtyp
|
|||||||
|
|
||||||
termStringInfo(&sql);
|
termStringInfo(&sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if PG_VERSION_NUM < 80400
|
|
||||||
|
|
||||||
int
|
|
||||||
SPI_execute_with_args(const char *src,
|
|
||||||
int nargs, Oid *argtypes,
|
|
||||||
Datum *values, const char *nulls,
|
|
||||||
bool read_only, long tcount)
|
|
||||||
{
|
|
||||||
SPIPlanPtr plan;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
plan = SPI_prepare(src, nargs, argtypes);
|
|
||||||
if (plan == NULL)
|
|
||||||
return SPI_result;
|
|
||||||
ret = SPI_execute_plan(plan, values, nulls, read_only, tcount);
|
|
||||||
SPI_freeplan(plan);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -12,11 +12,8 @@
|
|||||||
|
|
||||||
#include "executor/spi.h"
|
#include "executor/spi.h"
|
||||||
|
|
||||||
#if PG_VERSION_NUM < 80400
|
#ifdef _MSC_VER
|
||||||
|
#define __attribute__(x)
|
||||||
extern int SPI_execute_with_args(const char *src, int nargs, Oid *argtypes,
|
|
||||||
Datum *values, const char *nulls, bool read_only, long tcount);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void execute(int expected, const char *sql);
|
extern void execute(int expected, const char *sql);
|
||||||
|
53
lib/repack.c
53
lib/repack.c
@ -97,14 +97,6 @@ must_be_superuser(const char *func)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Include an implementation of RenameRelationInternal for old
|
|
||||||
* versions which don't have one.
|
|
||||||
*/
|
|
||||||
#if PG_VERSION_NUM < 80400
|
|
||||||
static void RenameRelationInternal(Oid myrelid, const char *newrelname, Oid namespaceId);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* The API of RenameRelationInternal() was changed in 9.2.
|
/* The API of RenameRelationInternal() was changed in 9.2.
|
||||||
* Use the RENAME_REL macro for compatibility across versions.
|
* Use the RENAME_REL macro for compatibility across versions.
|
||||||
*/
|
*/
|
||||||
@ -1020,19 +1012,6 @@ repack_drop(PG_FUNCTION_ARGS)
|
|||||||
--numobj;
|
--numobj;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PG_VERSION_NUM < 80400
|
|
||||||
/* delete autovacuum settings */
|
|
||||||
execute_with_format(
|
|
||||||
SPI_OK_DELETE,
|
|
||||||
"DELETE FROM pg_catalog.pg_autovacuum v"
|
|
||||||
" USING pg_class c, pg_namespace n"
|
|
||||||
" WHERE relname IN ('log_%u', 'table_%u')"
|
|
||||||
" AND n.nspname = 'repack'"
|
|
||||||
" AND c.relnamespace = n.oid"
|
|
||||||
" AND v.vacrelid = c.oid",
|
|
||||||
oid, oid);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* drop temp table */
|
/* drop temp table */
|
||||||
if (numobj > 0)
|
if (numobj > 0)
|
||||||
{
|
{
|
||||||
@ -1056,17 +1035,10 @@ repack_disable_autovacuum(PG_FUNCTION_ARGS)
|
|||||||
/* connect to SPI manager */
|
/* connect to SPI manager */
|
||||||
repack_init();
|
repack_init();
|
||||||
|
|
||||||
#if PG_VERSION_NUM >= 80400
|
|
||||||
execute_with_format(
|
execute_with_format(
|
||||||
SPI_OK_UTILITY,
|
SPI_OK_UTILITY,
|
||||||
"ALTER TABLE %s SET (autovacuum_enabled = off)",
|
"ALTER TABLE %s SET (autovacuum_enabled = off)",
|
||||||
get_relation_name(oid));
|
get_relation_name(oid));
|
||||||
#else
|
|
||||||
execute_with_format(
|
|
||||||
SPI_OK_INSERT,
|
|
||||||
"INSERT INTO pg_catalog.pg_autovacuum VALUES (%u, false, -1, -1, -1, -1, -1, -1, -1, -1)",
|
|
||||||
oid);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SPI_finish();
|
SPI_finish();
|
||||||
|
|
||||||
@ -1322,31 +1294,6 @@ repack_index_swap(PG_FUNCTION_ARGS)
|
|||||||
PG_RETURN_VOID();
|
PG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PG_VERSION_NUM < 80400
|
|
||||||
|
|
||||||
/* XXX: You might need to add PGDLLIMPORT into your miscadmin.h. */
|
|
||||||
extern PGDLLIMPORT bool allowSystemTableMods;
|
|
||||||
|
|
||||||
static void
|
|
||||||
RenameRelationInternal(Oid myrelid, const char *newrelname, Oid namespaceId)
|
|
||||||
{
|
|
||||||
bool save_allowSystemTableMods = allowSystemTableMods;
|
|
||||||
|
|
||||||
allowSystemTableMods = true;
|
|
||||||
PG_TRY();
|
|
||||||
{
|
|
||||||
renamerel(myrelid, newrelname, OBJECT_TABLE);
|
|
||||||
allowSystemTableMods = save_allowSystemTableMods;
|
|
||||||
}
|
|
||||||
PG_CATCH();
|
|
||||||
{
|
|
||||||
allowSystemTableMods = save_allowSystemTableMods;
|
|
||||||
PG_RE_THROW();
|
|
||||||
}
|
|
||||||
PG_END_TRY();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Datum
|
Datum
|
||||||
repack_get_table_and_inheritors(PG_FUNCTION_ARGS)
|
repack_get_table_and_inheritors(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
/*
|
|
||||||
* pg_repack: lib/uninstall_repack.sql
|
|
||||||
*
|
|
||||||
* Portions Copyright (c) 2008-2011, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
|
|
||||||
* Portions Copyright (c) 2011, Itagaki Takahiro
|
|
||||||
* Portions Copyright (c) 2012-2015, The Reorg Development Team
|
|
||||||
*/
|
|
||||||
|
|
||||||
DROP SCHEMA IF EXISTS repack CASCADE;
|
|
@ -17,26 +17,8 @@ INTVERSION := $(shell echo $$(($$(echo $(VERSION) | sed 's/\([[:digit:]]\{1,\}\)
|
|||||||
# Test suite
|
# Test suite
|
||||||
#
|
#
|
||||||
|
|
||||||
ifeq ($(shell echo $$(($(INTVERSION) >= 901))),1)
|
REGRESS := init-extension repack tablespace issue3
|
||||||
REGRESS := init-extension
|
|
||||||
else
|
|
||||||
REGRESS := init-legacy
|
|
||||||
endif
|
|
||||||
|
|
||||||
# plpgsql not available by default on pg < 9.0
|
|
||||||
ifeq ($(shell echo $$(($(INTVERSION) < 900))),1)
|
|
||||||
REGRESS += plpgsql
|
|
||||||
endif
|
|
||||||
|
|
||||||
REGRESS += repack tablespace
|
|
||||||
|
|
||||||
# This test depends on collate, not supported before 9.1
|
|
||||||
ifeq ($(shell echo $$(($(INTVERSION) >= 901))),1)
|
|
||||||
REGRESS += issue3
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
USE_PGXS = 1 # use pgxs if not in contrib directory
|
USE_PGXS = 1 # use pgxs if not in contrib directory
|
||||||
PG_CONFIG = pg_config
|
|
||||||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||||
include $(PGXS)
|
include $(PGXS)
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
SET client_min_messages = warning;
|
|
||||||
\set ECHO none
|
|
||||||
RESET client_min_messages;
|
|
@ -1 +0,0 @@
|
|||||||
CREATE LANGUAGE plpgsql;
|
|
@ -55,6 +55,20 @@ CREATE TABLE tbl_idxopts (
|
|||||||
t text
|
t text
|
||||||
);
|
);
|
||||||
CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa');
|
CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa');
|
||||||
|
-- Use this table to play with attribute options too
|
||||||
|
ALTER TABLE tbl_idxopts ALTER i SET STATISTICS 1;
|
||||||
|
ALTER TABLE tbl_idxopts ALTER t SET (n_distinct = -0.5);
|
||||||
|
CREATE TABLE tbl_with_toast (
|
||||||
|
i integer PRIMARY KEY,
|
||||||
|
c text
|
||||||
|
);
|
||||||
|
ALTER TABLE tbl_with_toast SET (AUTOVACUUM_VACUUM_SCALE_FACTOR = 30, AUTOVACUUM_VACUUM_THRESHOLD = 300);
|
||||||
|
ALTER TABLE tbl_with_toast SET (TOAST.AUTOVACUUM_VACUUM_SCALE_FACTOR = 40, TOAST.AUTOVACUUM_VACUUM_THRESHOLD = 400);
|
||||||
|
CREATE TABLE tbl_with_mod_column_storage (
|
||||||
|
id integer PRIMARY KEY,
|
||||||
|
c text
|
||||||
|
);
|
||||||
|
ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN;
|
||||||
--
|
--
|
||||||
-- insert data
|
-- insert data
|
||||||
--
|
--
|
||||||
@ -82,6 +96,8 @@ INSERT INTO tbl_with_dropped_toast VALUES(2, 20, sqrt(2::numeric(1000,999))::tex
|
|||||||
ALTER TABLE tbl_with_dropped_toast DROP COLUMN t;
|
ALTER TABLE tbl_with_dropped_toast DROP COLUMN t;
|
||||||
INSERT INTO tbl_badindex VALUES(1, 10);
|
INSERT INTO tbl_badindex VALUES(1, 10);
|
||||||
INSERT INTO tbl_badindex VALUES(2, 10);
|
INSERT INTO tbl_badindex VALUES(2, 10);
|
||||||
|
-- insert data that is always stored into the toast table if column type is extended.
|
||||||
|
INSERT INTO tbl_with_mod_column_storage SELECT 1, array_to_string(ARRAY(SELECT chr(code) FROM generate_series(33,3000) code), '');
|
||||||
-- This will fail. Silence the message as it's different across PG versions.
|
-- This will fail. Silence the message as it's different across PG versions.
|
||||||
SET client_min_messages = fatal;
|
SET client_min_messages = fatal;
|
||||||
CREATE UNIQUE INDEX CONCURRENTLY idx_badindex_n ON tbl_badindex (n);
|
CREATE UNIQUE INDEX CONCURRENTLY idx_badindex_n ON tbl_badindex (n);
|
||||||
@ -128,6 +144,8 @@ INFO: repacking table "tbl_with_dropped_toast"
|
|||||||
INFO: repacking table "tbl_badindex"
|
INFO: repacking table "tbl_badindex"
|
||||||
WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n)
|
WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n)
|
||||||
INFO: repacking table "tbl_idxopts"
|
INFO: repacking table "tbl_idxopts"
|
||||||
|
INFO: repacking table "tbl_with_toast"
|
||||||
|
INFO: repacking table "tbl_with_mod_column_storage"
|
||||||
--
|
--
|
||||||
-- after
|
-- after
|
||||||
--
|
--
|
||||||
@ -203,14 +221,14 @@ Indexes:
|
|||||||
"tbl_idxopts_pkey" PRIMARY KEY, btree (i)
|
"tbl_idxopts_pkey" PRIMARY KEY, btree (i)
|
||||||
"idxopts_t" btree (t DESC NULLS LAST) WHERE t <> 'aaa'::text
|
"idxopts_t" btree (t DESC NULLS LAST) WHERE t <> 'aaa'::text
|
||||||
|
|
||||||
SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster;
|
SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster ORDER BY 1, 2;
|
||||||
col1 | to_char | ,")
|
col1 | to_char | ,")
|
||||||
------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
1 | 2008-12-31 10:00:00 | admin
|
||||||
2 | 2008-01-01 00:00:00 | king
|
2 | 2008-01-01 00:00:00 | king
|
||||||
5 | 2008-01-01 00:30:00 | 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372352885092648612494977154218334204285686060146824720771435854874155657069677653720226485447015858801620758474922657226002085584466521458398893944370926591800311388246468157082630100594858704003186480342194897278290641045072636881313739855256117322040245091227700226941127573627280495738108967504018369868368450725799364729060762996941380475654823728997180326802474420629269124859052181004459842150591120249441341728531478105803603371077309182869314710171111683916581726889419758716582152128229518488471.732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248575675626141415406703029969945094998952478811655512094373648528093231902305582067974820101084674923265015312343266903322886650672254668921837971227047131660367861588019049986537379859389467650347506576050756618348129606100947602187190325083145829523959832997789824508288714463832917347224163984587855397667958063818353666110843173780894378316102088305524901670023520711144288695990956365797087168498072899493296484283020786408603988738697537582317317831395992983007838702877053913369563312103707264019249106768231199288375641141422016742752102372994270831059898459475987664288897796147837958390228854852903576033852808064381972344661059689722872865264153822664698420021195484155278441181286534507035191650016689294415480846071277143999762926834629577438361895110127148638746976545982451788550975379013880664961911962222957110555242923723192197738262561631468842032853716682938649611917049738836395495938
|
|
||||||
3 | 2008-03-04 12:00:00 | joker
|
3 | 2008-03-04 12:00:00 | joker
|
||||||
4 | 2008-03-05 15:00:00 | queen
|
4 | 2008-03-05 15:00:00 | queen
|
||||||
1 | 2008-12-31 10:00:00 | admin
|
5 | 2008-01-01 00:30:00 | 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372352885092648612494977154218334204285686060146824720771435854874155657069677653720226485447015858801620758474922657226002085584466521458398893944370926591800311388246468157082630100594858704003186480342194897278290641045072636881313739855256117322040245091227700226941127573627280495738108967504018369868368450725799364729060762996941380475654823728997180326802474420629269124859052181004459842150591120249441341728531478105803603371077309182869314710171111683916581726889419758716582152128229518488471.732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248575675626141415406703029969945094998952478811655512094373648528093231902305582067974820101084674923265015312343266903322886650672254668921837971227047131660367861588019049986537379859389467650347506576050756618348129606100947602187190325083145829523959832997789824508288714463832917347224163984587855397667958063818353666110843173780894378316102088305524901670023520711144288695990956365797087168498072899493296484283020786408603988738697537582317317831395992983007838702877053913369563312103707264019249106768231199288375641141422016742752102372994270831059898459475987664288897796147837958390228854852903576033852808064381972344661059689722872865264153822664698420021195484155278441181286534507035191650016689294415480846071277143999762926834629577438361895110127148638746976545982451788550975379013880664961911962222957110555242923723192197738262561631468842032853716682938649611917049738836395495938
|
||||||
(5 rows)
|
(5 rows)
|
||||||
|
|
||||||
SELECT * FROM tbl_only_ckey ORDER BY 1;
|
SELECT * FROM tbl_only_ckey ORDER BY 1;
|
||||||
@ -236,14 +254,14 @@ SELECT * FROM tbl_gistkey ORDER BY 1;
|
|||||||
|
|
||||||
SET enable_seqscan = on;
|
SET enable_seqscan = on;
|
||||||
SET enable_indexscan = off;
|
SET enable_indexscan = off;
|
||||||
SELECT * FROM tbl_with_dropped_column;
|
SELECT * FROM tbl_with_dropped_column ;
|
||||||
c1 | id | c2 | c3
|
c1 | id | c2 | c3
|
||||||
----+----+----+----
|
----+----+----+----
|
||||||
c1 | 1 | c2 |
|
|
||||||
c1 | 2 | c2 |
|
c1 | 2 | c2 |
|
||||||
|
c1 | 1 | c2 |
|
||||||
(2 rows)
|
(2 rows)
|
||||||
|
|
||||||
SELECT * FROM view_for_dropped_column;
|
SELECT * FROM view_for_dropped_column ORDER BY 1, 2;
|
||||||
c1 | id | c2 | c3
|
c1 | id | c2 | c3
|
||||||
----+----+----+----
|
----+----+----+----
|
||||||
c1 | 1 | c2 |
|
c1 | 1 | c2 |
|
||||||
@ -259,7 +277,7 @@ SELECT * FROM tbl_with_dropped_toast;
|
|||||||
|
|
||||||
SET enable_seqscan = off;
|
SET enable_seqscan = off;
|
||||||
SET enable_indexscan = on;
|
SET enable_indexscan = on;
|
||||||
SELECT * FROM tbl_with_dropped_column;
|
SELECT * FROM tbl_with_dropped_column ORDER BY 1, 2;
|
||||||
c1 | id | c2 | c3
|
c1 | id | c2 | c3
|
||||||
----+----+----+----
|
----+----+----+----
|
||||||
c1 | 1 | c2 |
|
c1 | 1 | c2 |
|
||||||
@ -269,8 +287,8 @@ SELECT * FROM tbl_with_dropped_column;
|
|||||||
SELECT * FROM view_for_dropped_column;
|
SELECT * FROM view_for_dropped_column;
|
||||||
c1 | id | c2 | c3
|
c1 | id | c2 | c3
|
||||||
----+----+----+----
|
----+----+----+----
|
||||||
c1 | 1 | c2 |
|
|
||||||
c1 | 2 | c2 |
|
c1 | 2 | c2 |
|
||||||
|
c1 | 1 | c2 |
|
||||||
(2 rows)
|
(2 rows)
|
||||||
|
|
||||||
SELECT * FROM tbl_with_dropped_toast;
|
SELECT * FROM tbl_with_dropped_toast;
|
||||||
@ -282,6 +300,27 @@ SELECT * FROM tbl_with_dropped_toast;
|
|||||||
|
|
||||||
RESET enable_seqscan;
|
RESET enable_seqscan;
|
||||||
RESET enable_indexscan;
|
RESET enable_indexscan;
|
||||||
|
-- check if storage option for both table and TOAST table didn't go away.
|
||||||
|
SELECT CASE relkind
|
||||||
|
WHEN 'r' THEN relname
|
||||||
|
WHEN 't' THEN 'toast_table'
|
||||||
|
END as table,
|
||||||
|
reloptions
|
||||||
|
FROM pg_class
|
||||||
|
WHERE relname = 'tbl_with_toast' OR relname = 'pg_toast_' || 'tbl_with_toast'::regclass::oid
|
||||||
|
ORDER BY 1;
|
||||||
|
table | reloptions
|
||||||
|
----------------+---------------------------------------------------------------------
|
||||||
|
tbl_with_toast | {autovacuum_vacuum_scale_factor=30,autovacuum_vacuum_threshold=300}
|
||||||
|
toast_table | {autovacuum_vacuum_scale_factor=40,autovacuum_vacuum_threshold=400}
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
|
SELECT pg_relation_size(reltoastrelid) = 0 as check_toast_rel_size FROM pg_class WHERE relname = 'tbl_with_mod_column_storage';
|
||||||
|
check_toast_rel_size
|
||||||
|
----------------------
|
||||||
|
t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
--
|
--
|
||||||
-- check broken links or orphan toast relations
|
-- check broken links or orphan toast relations
|
||||||
--
|
--
|
||||||
@ -302,6 +341,18 @@ SELECT oid, relname
|
|||||||
-----+---------
|
-----+---------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
|
-- check columns options
|
||||||
|
SELECT attname, attstattarget, attoptions
|
||||||
|
FROM pg_attribute
|
||||||
|
WHERE attrelid = 'tbl_idxopts'::regclass
|
||||||
|
AND attnum > 0
|
||||||
|
ORDER BY attnum;
|
||||||
|
attname | attstattarget | attoptions
|
||||||
|
---------+---------------+-------------------
|
||||||
|
i | 1 |
|
||||||
|
t | -1 | {n_distinct=-0.5}
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
--
|
--
|
||||||
-- NOT NULL UNIQUE
|
-- NOT NULL UNIQUE
|
||||||
--
|
--
|
||||||
|
@ -55,6 +55,20 @@ CREATE TABLE tbl_idxopts (
|
|||||||
t text
|
t text
|
||||||
);
|
);
|
||||||
CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa');
|
CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa');
|
||||||
|
-- Use this table to play with attribute options too
|
||||||
|
ALTER TABLE tbl_idxopts ALTER i SET STATISTICS 1;
|
||||||
|
ALTER TABLE tbl_idxopts ALTER t SET (n_distinct = -0.5);
|
||||||
|
CREATE TABLE tbl_with_toast (
|
||||||
|
i integer PRIMARY KEY,
|
||||||
|
c text
|
||||||
|
);
|
||||||
|
ALTER TABLE tbl_with_toast SET (AUTOVACUUM_VACUUM_SCALE_FACTOR = 30, AUTOVACUUM_VACUUM_THRESHOLD = 300);
|
||||||
|
ALTER TABLE tbl_with_toast SET (TOAST.AUTOVACUUM_VACUUM_SCALE_FACTOR = 40, TOAST.AUTOVACUUM_VACUUM_THRESHOLD = 400);
|
||||||
|
CREATE TABLE tbl_with_mod_column_storage (
|
||||||
|
id integer PRIMARY KEY,
|
||||||
|
c text
|
||||||
|
);
|
||||||
|
ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN;
|
||||||
--
|
--
|
||||||
-- insert data
|
-- insert data
|
||||||
--
|
--
|
||||||
@ -82,6 +96,8 @@ INSERT INTO tbl_with_dropped_toast VALUES(2, 20, sqrt(2::numeric(1000,999))::tex
|
|||||||
ALTER TABLE tbl_with_dropped_toast DROP COLUMN t;
|
ALTER TABLE tbl_with_dropped_toast DROP COLUMN t;
|
||||||
INSERT INTO tbl_badindex VALUES(1, 10);
|
INSERT INTO tbl_badindex VALUES(1, 10);
|
||||||
INSERT INTO tbl_badindex VALUES(2, 10);
|
INSERT INTO tbl_badindex VALUES(2, 10);
|
||||||
|
-- insert data that is always stored into the toast table if column type is extended.
|
||||||
|
INSERT INTO tbl_with_mod_column_storage SELECT 1, array_to_string(ARRAY(SELECT chr(code) FROM generate_series(33,3000) code), '');
|
||||||
-- This will fail. Silence the message as it's different across PG versions.
|
-- This will fail. Silence the message as it's different across PG versions.
|
||||||
SET client_min_messages = fatal;
|
SET client_min_messages = fatal;
|
||||||
CREATE UNIQUE INDEX CONCURRENTLY idx_badindex_n ON tbl_badindex (n);
|
CREATE UNIQUE INDEX CONCURRENTLY idx_badindex_n ON tbl_badindex (n);
|
||||||
@ -128,6 +144,8 @@ INFO: repacking table "tbl_with_dropped_toast"
|
|||||||
INFO: repacking table "tbl_badindex"
|
INFO: repacking table "tbl_badindex"
|
||||||
WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n)
|
WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n)
|
||||||
INFO: repacking table "tbl_idxopts"
|
INFO: repacking table "tbl_idxopts"
|
||||||
|
INFO: repacking table "tbl_with_toast"
|
||||||
|
INFO: repacking table "tbl_with_mod_column_storage"
|
||||||
--
|
--
|
||||||
-- after
|
-- after
|
||||||
--
|
--
|
||||||
@ -139,8 +157,8 @@ INFO: repacking table "tbl_idxopts"
|
|||||||
time | timestamp without time zone |
|
time | timestamp without time zone |
|
||||||
,") | text | not null
|
,") | text | not null
|
||||||
Indexes:
|
Indexes:
|
||||||
"tbl_cluster_pkey" PRIMARY KEY, btree (","")", col1) WITH (fillfactor=75)
|
"tbl_cluster_pkey" PRIMARY KEY, btree (","")", col1) WITH (fillfactor='75')
|
||||||
",") cluster" btree ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor=75) CLUSTER
|
",") cluster" btree ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor='75') CLUSTER
|
||||||
|
|
||||||
\d tbl_gistkey
|
\d tbl_gistkey
|
||||||
Table "public.tbl_gistkey"
|
Table "public.tbl_gistkey"
|
||||||
@ -180,8 +198,8 @@ Table "public.tbl_with_dropped_column"
|
|||||||
c2 | text |
|
c2 | text |
|
||||||
c3 | text |
|
c3 | text |
|
||||||
Indexes:
|
Indexes:
|
||||||
"tbl_with_dropped_column_pkey" PRIMARY KEY, btree (id) WITH (fillfactor=75) CLUSTER
|
"tbl_with_dropped_column_pkey" PRIMARY KEY, btree (id) WITH (fillfactor='75') CLUSTER
|
||||||
"idx_c1c2" btree (c1, c2) WITH (fillfactor=75)
|
"idx_c1c2" btree (c1, c2) WITH (fillfactor='75')
|
||||||
"idx_c2c1" btree (c2, c1)
|
"idx_c2c1" btree (c2, c1)
|
||||||
|
|
||||||
\d tbl_with_dropped_toast
|
\d tbl_with_dropped_toast
|
||||||
@ -203,14 +221,14 @@ Indexes:
|
|||||||
"tbl_idxopts_pkey" PRIMARY KEY, btree (i)
|
"tbl_idxopts_pkey" PRIMARY KEY, btree (i)
|
||||||
"idxopts_t" btree (t DESC NULLS LAST) WHERE t <> 'aaa'::text
|
"idxopts_t" btree (t DESC NULLS LAST) WHERE t <> 'aaa'::text
|
||||||
|
|
||||||
SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster;
|
SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster ORDER BY 1, 2;
|
||||||
col1 | to_char | ,")
|
col1 | to_char | ,")
|
||||||
------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
1 | 2008-12-31 10:00:00 | admin
|
||||||
2 | 2008-01-01 00:00:00 | king
|
2 | 2008-01-01 00:00:00 | king
|
||||||
5 | 2008-01-01 00:30:00 | 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372352885092648612494977154218334204285686060146824720771435854874155657069677653720226485447015858801620758474922657226002085584466521458398893944370926591800311388246468157082630100594858704003186480342194897278290641045072636881313739855256117322040245091227700226941127573627280495738108967504018369868368450725799364729060762996941380475654823728997180326802474420629269124859052181004459842150591120249441341728531478105803603371077309182869314710171111683916581726889419758716582152128229518488471.732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248575675626141415406703029969945094998952478811655512094373648528093231902305582067974820101084674923265015312343266903322886650672254668921837971227047131660367861588019049986537379859389467650347506576050756618348129606100947602187190325083145829523959832997789824508288714463832917347224163984587855397667958063818353666110843173780894378316102088305524901670023520711144288695990956365797087168498072899493296484283020786408603988738697537582317317831395992983007838702877053913369563312103707264019249106768231199288375641141422016742752102372994270831059898459475987664288897796147837958390228854852903576033852808064381972344661059689722872865264153822664698420021195484155278441181286534507035191650016689294415480846071277143999762926834629577438361895110127148638746976545982451788550975379013880664961911962222957110555242923723192197738262561631468842032853716682938649611917049738836395495938
|
|
||||||
3 | 2008-03-04 12:00:00 | joker
|
3 | 2008-03-04 12:00:00 | joker
|
||||||
4 | 2008-03-05 15:00:00 | queen
|
4 | 2008-03-05 15:00:00 | queen
|
||||||
1 | 2008-12-31 10:00:00 | admin
|
5 | 2008-01-01 00:30:00 | 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372352885092648612494977154218334204285686060146824720771435854874155657069677653720226485447015858801620758474922657226002085584466521458398893944370926591800311388246468157082630100594858704003186480342194897278290641045072636881313739855256117322040245091227700226941127573627280495738108967504018369868368450725799364729060762996941380475654823728997180326802474420629269124859052181004459842150591120249441341728531478105803603371077309182869314710171111683916581726889419758716582152128229518488471.732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248575675626141415406703029969945094998952478811655512094373648528093231902305582067974820101084674923265015312343266903322886650672254668921837971227047131660367861588019049986537379859389467650347506576050756618348129606100947602187190325083145829523959832997789824508288714463832917347224163984587855397667958063818353666110843173780894378316102088305524901670023520711144288695990956365797087168498072899493296484283020786408603988738697537582317317831395992983007838702877053913369563312103707264019249106768231199288375641141422016742752102372994270831059898459475987664288897796147837958390228854852903576033852808064381972344661059689722872865264153822664698420021195484155278441181286534507035191650016689294415480846071277143999762926834629577438361895110127148638746976545982451788550975379013880664961911962222957110555242923723192197738262561631468842032853716682938649611917049738836395495938
|
||||||
(5 rows)
|
(5 rows)
|
||||||
|
|
||||||
SELECT * FROM tbl_only_ckey ORDER BY 1;
|
SELECT * FROM tbl_only_ckey ORDER BY 1;
|
||||||
@ -236,14 +254,14 @@ SELECT * FROM tbl_gistkey ORDER BY 1;
|
|||||||
|
|
||||||
SET enable_seqscan = on;
|
SET enable_seqscan = on;
|
||||||
SET enable_indexscan = off;
|
SET enable_indexscan = off;
|
||||||
SELECT * FROM tbl_with_dropped_column;
|
SELECT * FROM tbl_with_dropped_column ;
|
||||||
c1 | id | c2 | c3
|
c1 | id | c2 | c3
|
||||||
----+----+----+----
|
----+----+----+----
|
||||||
c1 | 1 | c2 |
|
|
||||||
c1 | 2 | c2 |
|
c1 | 2 | c2 |
|
||||||
|
c1 | 1 | c2 |
|
||||||
(2 rows)
|
(2 rows)
|
||||||
|
|
||||||
SELECT * FROM view_for_dropped_column;
|
SELECT * FROM view_for_dropped_column ORDER BY 1, 2;
|
||||||
c1 | id | c2 | c3
|
c1 | id | c2 | c3
|
||||||
----+----+----+----
|
----+----+----+----
|
||||||
c1 | 1 | c2 |
|
c1 | 1 | c2 |
|
||||||
@ -259,7 +277,7 @@ SELECT * FROM tbl_with_dropped_toast;
|
|||||||
|
|
||||||
SET enable_seqscan = off;
|
SET enable_seqscan = off;
|
||||||
SET enable_indexscan = on;
|
SET enable_indexscan = on;
|
||||||
SELECT * FROM tbl_with_dropped_column;
|
SELECT * FROM tbl_with_dropped_column ORDER BY 1, 2;
|
||||||
c1 | id | c2 | c3
|
c1 | id | c2 | c3
|
||||||
----+----+----+----
|
----+----+----+----
|
||||||
c1 | 1 | c2 |
|
c1 | 1 | c2 |
|
||||||
@ -269,8 +287,8 @@ SELECT * FROM tbl_with_dropped_column;
|
|||||||
SELECT * FROM view_for_dropped_column;
|
SELECT * FROM view_for_dropped_column;
|
||||||
c1 | id | c2 | c3
|
c1 | id | c2 | c3
|
||||||
----+----+----+----
|
----+----+----+----
|
||||||
c1 | 1 | c2 |
|
|
||||||
c1 | 2 | c2 |
|
c1 | 2 | c2 |
|
||||||
|
c1 | 1 | c2 |
|
||||||
(2 rows)
|
(2 rows)
|
||||||
|
|
||||||
SELECT * FROM tbl_with_dropped_toast;
|
SELECT * FROM tbl_with_dropped_toast;
|
||||||
@ -282,6 +300,27 @@ SELECT * FROM tbl_with_dropped_toast;
|
|||||||
|
|
||||||
RESET enable_seqscan;
|
RESET enable_seqscan;
|
||||||
RESET enable_indexscan;
|
RESET enable_indexscan;
|
||||||
|
-- check if storage option for both table and TOAST table didn't go away.
|
||||||
|
SELECT CASE relkind
|
||||||
|
WHEN 'r' THEN relname
|
||||||
|
WHEN 't' THEN 'toast_table'
|
||||||
|
END as table,
|
||||||
|
reloptions
|
||||||
|
FROM pg_class
|
||||||
|
WHERE relname = 'tbl_with_toast' OR relname = 'pg_toast_' || 'tbl_with_toast'::regclass::oid
|
||||||
|
ORDER BY 1;
|
||||||
|
table | reloptions
|
||||||
|
----------------+---------------------------------------------------------------------
|
||||||
|
tbl_with_toast | {autovacuum_vacuum_scale_factor=30,autovacuum_vacuum_threshold=300}
|
||||||
|
toast_table | {autovacuum_vacuum_scale_factor=40,autovacuum_vacuum_threshold=400}
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
|
SELECT pg_relation_size(reltoastrelid) = 0 as check_toast_rel_size FROM pg_class WHERE relname = 'tbl_with_mod_column_storage';
|
||||||
|
check_toast_rel_size
|
||||||
|
----------------------
|
||||||
|
t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
--
|
--
|
||||||
-- check broken links or orphan toast relations
|
-- check broken links or orphan toast relations
|
||||||
--
|
--
|
||||||
@ -302,6 +341,18 @@ SELECT oid, relname
|
|||||||
-----+---------
|
-----+---------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
|
-- check columns options
|
||||||
|
SELECT attname, attstattarget, attoptions
|
||||||
|
FROM pg_attribute
|
||||||
|
WHERE attrelid = 'tbl_idxopts'::regclass
|
||||||
|
AND attnum > 0
|
||||||
|
ORDER BY attnum;
|
||||||
|
attname | attstattarget | attoptions
|
||||||
|
---------+---------------+-------------------
|
||||||
|
i | 1 |
|
||||||
|
t | -1 | {n_distinct=-0.5}
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
--
|
--
|
||||||
-- NOT NULL UNIQUE
|
-- NOT NULL UNIQUE
|
||||||
--
|
--
|
||||||
@ -325,7 +376,7 @@ INFO: repacking table "tbl_pk_uk"
|
|||||||
-- => OK
|
-- => OK
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk --only-indexes
|
\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk --only-indexes
|
||||||
INFO: repacking indexes of "tbl_pk_uk"
|
INFO: repacking indexes of "tbl_pk_uk"
|
||||||
INFO: repacking index "public"."tbl_pk_uk_col2_key"
|
INFO: repacking index "public"."tbl_pk_uk_col2_col1_key"
|
||||||
INFO: repacking index "public"."tbl_pk_uk_pkey"
|
INFO: repacking index "public"."tbl_pk_uk_pkey"
|
||||||
-- => OK
|
-- => OK
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_nn_puk
|
\! pg_repack --dbname=contrib_regression --table=tbl_nn_puk
|
||||||
@ -338,25 +389,19 @@ CREATE FUNCTION trgtest() RETURNS trigger AS
|
|||||||
$$BEGIN RETURN NEW; END$$
|
$$BEGIN RETURN NEW; END$$
|
||||||
LANGUAGE plpgsql;
|
LANGUAGE plpgsql;
|
||||||
CREATE TABLE trg1 (id integer PRIMARY KEY);
|
CREATE TABLE trg1 (id integer PRIMARY KEY);
|
||||||
CREATE TRIGGER z_repack_triggeq BEFORE UPDATE ON trg1 FOR EACH ROW EXECUTE PROCEDURE trgtest();
|
CREATE TRIGGER repack_trigger_1 AFTER UPDATE ON trg1 FOR EACH ROW EXECUTE PROCEDURE trgtest();
|
||||||
\! pg_repack --dbname=contrib_regression --table=trg1
|
\! pg_repack --dbname=contrib_regression --table=trg1
|
||||||
INFO: repacking table "trg1"
|
INFO: repacking table "trg1"
|
||||||
CREATE TABLE trg2 (id integer PRIMARY KEY);
|
CREATE TABLE trg2 (id integer PRIMARY KEY);
|
||||||
CREATE TRIGGER z_repack_trigger BEFORE UPDATE ON trg2 FOR EACH ROW EXECUTE PROCEDURE trgtest();
|
CREATE TRIGGER repack_trigger AFTER UPDATE ON trg2 FOR EACH ROW EXECUTE PROCEDURE trgtest();
|
||||||
\! pg_repack --dbname=contrib_regression --table=trg2
|
\! pg_repack --dbname=contrib_regression --table=trg2
|
||||||
INFO: repacking table "trg2"
|
INFO: repacking table "trg2"
|
||||||
WARNING: the table "trg2" already has a trigger called "z_repack_trigger"
|
WARNING: the table "trg2" already has a trigger called "repack_trigger"
|
||||||
DETAIL: The trigger was probably installed during a previous attempt to run pg_repack on the table which was interrupted and for some reason failed to clean up the temporary objects. Please drop the trigger or drop and recreate the pg_repack extension altogether to remove all the temporary objects left over.
|
DETAIL: The trigger was probably installed during a previous attempt to run pg_repack on the table which was interrupted and for some reason failed to clean up the temporary objects. Please drop the trigger or drop and recreate the pg_repack extension altogether to remove all the temporary objects left over.
|
||||||
CREATE TABLE trg3 (id integer PRIMARY KEY);
|
CREATE TABLE trg3 (id integer PRIMARY KEY);
|
||||||
CREATE TRIGGER z_repack_trigges BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest();
|
CREATE TRIGGER repack_trigger_1 BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest();
|
||||||
\! pg_repack --dbname=contrib_regression --table=trg3
|
\! pg_repack --dbname=contrib_regression --table=trg3
|
||||||
INFO: repacking table "trg3"
|
INFO: repacking table "trg3"
|
||||||
WARNING: trigger "z_repack_trigges" conflicting on table "trg3"
|
|
||||||
DETAIL: The trigger "z_repack_trigger" must be the last of the BEFORE triggers to fire on the table (triggers fire in alphabetical order). Please rename the trigger so that it sorts before "z_repack_trigger": you can use "ALTER TRIGGER z_repack_trigges ON trg3 RENAME TO newname".
|
|
||||||
CREATE TABLE trg4 (id integer PRIMARY KEY);
|
|
||||||
CREATE TRIGGER zzzzzz AFTER UPDATE ON trg4 FOR EACH ROW EXECUTE PROCEDURE trgtest();
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=trg4
|
|
||||||
INFO: repacking table "trg4"
|
|
||||||
--
|
--
|
||||||
-- Dry run
|
-- Dry run
|
||||||
--
|
--
|
||||||
@ -387,3 +432,43 @@ ERROR: cannot repack specific table(s) in schema, use schema.table notation inst
|
|||||||
-- => ERROR
|
-- => ERROR
|
||||||
\! pg_repack --dbname=contrib_regression --all --schema=test_schema1
|
\! pg_repack --dbname=contrib_regression --all --schema=test_schema1
|
||||||
ERROR: cannot repack specific schema(s) in all databases
|
ERROR: cannot repack specific schema(s) in all databases
|
||||||
|
--
|
||||||
|
-- don't kill backend
|
||||||
|
--
|
||||||
|
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-kill-backend
|
||||||
|
INFO: repacking table "tbl_cluster"
|
||||||
|
--
|
||||||
|
-- no superuser check
|
||||||
|
--
|
||||||
|
DROP ROLE IF EXISTS nosuper;
|
||||||
|
CREATE ROLE nosuper WITH LOGIN;
|
||||||
|
-- => OK
|
||||||
|
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-superuser-check
|
||||||
|
INFO: repacking table "tbl_cluster"
|
||||||
|
-- => ERROR
|
||||||
|
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper
|
||||||
|
ERROR: pg_repack failed with error: You must be a superuser to use pg_repack
|
||||||
|
-- => ERROR
|
||||||
|
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper --no-superuser-check
|
||||||
|
ERROR: pg_repack failed with error: ERROR: permission denied for schema repack
|
||||||
|
DROP ROLE IF EXISTS nosuper;
|
||||||
|
--
|
||||||
|
-- exclude extension check
|
||||||
|
--
|
||||||
|
CREATE SCHEMA exclude_extension_schema;
|
||||||
|
CREATE TABLE exclude_extension_schema.tbl(val integer primary key);
|
||||||
|
-- => ERROR
|
||||||
|
\! pg_repack --dbname=contrib_regression --table=dummy_table --exclude-extension=dummy_extension
|
||||||
|
ERROR: cannot specify --table (-t) and --exclude-extension (-C)
|
||||||
|
-- => ERROR
|
||||||
|
\! pg_repack --dbname=contrib_regression --table=dummy_table --exclude-extension=dummy_extension -x
|
||||||
|
ERROR: cannot specify --only-indexes (-x) and --exclude-extension (-C)
|
||||||
|
-- => ERROR
|
||||||
|
\! pg_repack --dbname=contrib_regression --index=dummy_index --exclude-extension=dummy_extension
|
||||||
|
ERROR: cannot specify --index (-i) and --exclude-extension (-C)
|
||||||
|
-- => OK
|
||||||
|
\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension
|
||||||
|
INFO: repacking table "exclude_extension_schema.tbl"
|
||||||
|
-- => OK
|
||||||
|
\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension --exclude-extension=dummy_extension
|
||||||
|
INFO: repacking table "exclude_extension_schema.tbl"
|
||||||
|
@ -1,389 +0,0 @@
|
|||||||
SET client_min_messages = warning;
|
|
||||||
--
|
|
||||||
-- create table.
|
|
||||||
--
|
|
||||||
CREATE TABLE tbl_cluster (
|
|
||||||
col1 int,
|
|
||||||
"time" timestamp,
|
|
||||||
","")" text,
|
|
||||||
PRIMARY KEY (","")", col1) WITH (fillfactor = 75)
|
|
||||||
) WITH (fillfactor = 70);
|
|
||||||
CREATE INDEX ","") cluster" ON tbl_cluster ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor = 75);
|
|
||||||
ALTER TABLE tbl_cluster CLUSTER ON ","") cluster";
|
|
||||||
CREATE TABLE tbl_only_pkey (
|
|
||||||
col1 int PRIMARY KEY,
|
|
||||||
","")" text
|
|
||||||
);
|
|
||||||
CREATE TABLE tbl_only_ckey (
|
|
||||||
col1 int,
|
|
||||||
col2 timestamp,
|
|
||||||
","")" text
|
|
||||||
) WITH (fillfactor = 70);
|
|
||||||
CREATE INDEX cidx_only_ckey ON tbl_only_ckey (col2, ","")");
|
|
||||||
ALTER TABLE tbl_only_ckey CLUSTER ON cidx_only_ckey;
|
|
||||||
CREATE TABLE tbl_gistkey (
|
|
||||||
id integer PRIMARY KEY,
|
|
||||||
c circle
|
|
||||||
);
|
|
||||||
CREATE INDEX cidx_circle ON tbl_gistkey USING gist (c);
|
|
||||||
ALTER TABLE tbl_gistkey CLUSTER ON cidx_circle;
|
|
||||||
CREATE TABLE tbl_with_dropped_column (
|
|
||||||
d1 text,
|
|
||||||
c1 text,
|
|
||||||
id integer PRIMARY KEY,
|
|
||||||
d2 text,
|
|
||||||
c2 text,
|
|
||||||
d3 text
|
|
||||||
);
|
|
||||||
ALTER INDEX tbl_with_dropped_column_pkey SET (fillfactor = 75);
|
|
||||||
ALTER TABLE tbl_with_dropped_column CLUSTER ON tbl_with_dropped_column_pkey;
|
|
||||||
CREATE INDEX idx_c1c2 ON tbl_with_dropped_column (c1, c2) WITH (fillfactor = 75);
|
|
||||||
CREATE INDEX idx_c2c1 ON tbl_with_dropped_column (c2, c1);
|
|
||||||
CREATE TABLE tbl_with_dropped_toast (
|
|
||||||
i integer,
|
|
||||||
j integer,
|
|
||||||
t text,
|
|
||||||
PRIMARY KEY (i, j)
|
|
||||||
);
|
|
||||||
ALTER TABLE tbl_with_dropped_toast CLUSTER ON tbl_with_dropped_toast_pkey;
|
|
||||||
CREATE TABLE tbl_badindex (
|
|
||||||
id integer PRIMARY KEY,
|
|
||||||
n integer
|
|
||||||
);
|
|
||||||
CREATE TABLE tbl_idxopts (
|
|
||||||
i integer PRIMARY KEY,
|
|
||||||
t text
|
|
||||||
);
|
|
||||||
CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa');
|
|
||||||
--
|
|
||||||
-- insert data
|
|
||||||
--
|
|
||||||
INSERT INTO tbl_cluster VALUES(1, '2008-12-31 10:00:00', 'admin');
|
|
||||||
INSERT INTO tbl_cluster VALUES(2, '2008-01-01 00:00:00', 'king');
|
|
||||||
INSERT INTO tbl_cluster VALUES(3, '2008-03-04 12:00:00', 'joker');
|
|
||||||
INSERT INTO tbl_cluster VALUES(4, '2008-03-05 15:00:00', 'queen');
|
|
||||||
INSERT INTO tbl_cluster VALUES(5, '2008-01-01 00:30:00', sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text);
|
|
||||||
INSERT INTO tbl_only_pkey VALUES(1, 'abc');
|
|
||||||
INSERT INTO tbl_only_pkey VALUES(2, 'def');
|
|
||||||
INSERT INTO tbl_only_ckey VALUES(1, '2008-01-01 00:00:00', 'abc');
|
|
||||||
INSERT INTO tbl_only_ckey VALUES(2, '2008-02-01 00:00:00', 'def');
|
|
||||||
INSERT INTO tbl_gistkey VALUES(1, '<(1,2),3>');
|
|
||||||
INSERT INTO tbl_gistkey VALUES(2, '<(4,5),6>');
|
|
||||||
INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 2, 'd2', 'c2', 'd3');
|
|
||||||
INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 1, 'd2', 'c2', 'd3');
|
|
||||||
ALTER TABLE tbl_with_dropped_column DROP COLUMN d1;
|
|
||||||
ALTER TABLE tbl_with_dropped_column DROP COLUMN d2;
|
|
||||||
ALTER TABLE tbl_with_dropped_column DROP COLUMN d3;
|
|
||||||
ALTER TABLE tbl_with_dropped_column ADD COLUMN c3 text;
|
|
||||||
CREATE VIEW view_for_dropped_column AS
|
|
||||||
SELECT * FROM tbl_with_dropped_column;
|
|
||||||
INSERT INTO tbl_with_dropped_toast VALUES(1, 10, 'abc');
|
|
||||||
INSERT INTO tbl_with_dropped_toast VALUES(2, 20, sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text);
|
|
||||||
ALTER TABLE tbl_with_dropped_toast DROP COLUMN t;
|
|
||||||
INSERT INTO tbl_badindex VALUES(1, 10);
|
|
||||||
INSERT INTO tbl_badindex VALUES(2, 10);
|
|
||||||
-- This will fail. Silence the message as it's different across PG versions.
|
|
||||||
SET client_min_messages = fatal;
|
|
||||||
CREATE UNIQUE INDEX CONCURRENTLY idx_badindex_n ON tbl_badindex (n);
|
|
||||||
SET client_min_messages = warning;
|
|
||||||
INSERT INTO tbl_idxopts VALUES (0, 'abc'), (1, 'aaa'), (2, NULL), (3, 'bbb');
|
|
||||||
--
|
|
||||||
-- before
|
|
||||||
--
|
|
||||||
SELECT * FROM tbl_with_dropped_column;
|
|
||||||
c1 | id | c2 | c3
|
|
||||||
----+----+----+----
|
|
||||||
c1 | 2 | c2 |
|
|
||||||
c1 | 1 | c2 |
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SELECT * FROM view_for_dropped_column;
|
|
||||||
c1 | id | c2 | c3
|
|
||||||
----+----+----+----
|
|
||||||
c1 | 2 | c2 |
|
|
||||||
c1 | 1 | c2 |
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SELECT * FROM tbl_with_dropped_toast;
|
|
||||||
i | j
|
|
||||||
---+----
|
|
||||||
1 | 10
|
|
||||||
2 | 20
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
--
|
|
||||||
-- do repack
|
|
||||||
--
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_cluster
|
|
||||||
INFO: repacking table "tbl_cluster"
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_badindex
|
|
||||||
INFO: repacking table "tbl_badindex"
|
|
||||||
WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n)
|
|
||||||
\! pg_repack --dbname=contrib_regression
|
|
||||||
INFO: repacking table "tbl_cluster"
|
|
||||||
INFO: repacking table "tbl_only_pkey"
|
|
||||||
INFO: repacking table "tbl_gistkey"
|
|
||||||
INFO: repacking table "tbl_with_dropped_column"
|
|
||||||
INFO: repacking table "tbl_with_dropped_toast"
|
|
||||||
INFO: repacking table "tbl_badindex"
|
|
||||||
WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n)
|
|
||||||
INFO: repacking table "tbl_idxopts"
|
|
||||||
--
|
|
||||||
-- after
|
|
||||||
--
|
|
||||||
\d tbl_cluster
|
|
||||||
Table "public.tbl_cluster"
|
|
||||||
Column | Type | Modifiers
|
|
||||||
--------+-----------------------------+-----------
|
|
||||||
col1 | integer | not null
|
|
||||||
time | timestamp without time zone |
|
|
||||||
,") | text | not null
|
|
||||||
Indexes:
|
|
||||||
"tbl_cluster_pkey" PRIMARY KEY, btree (","")", col1) WITH (fillfactor=75)
|
|
||||||
",") cluster" btree ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor=75) CLUSTER
|
|
||||||
|
|
||||||
\d tbl_gistkey
|
|
||||||
Table "public.tbl_gistkey"
|
|
||||||
Column | Type | Modifiers
|
|
||||||
--------+---------+-----------
|
|
||||||
id | integer | not null
|
|
||||||
c | circle |
|
|
||||||
Indexes:
|
|
||||||
"tbl_gistkey_pkey" PRIMARY KEY, btree (id)
|
|
||||||
"cidx_circle" gist (c) CLUSTER
|
|
||||||
|
|
||||||
\d tbl_only_ckey
|
|
||||||
Table "public.tbl_only_ckey"
|
|
||||||
Column | Type | Modifiers
|
|
||||||
--------+-----------------------------+-----------
|
|
||||||
col1 | integer |
|
|
||||||
col2 | timestamp without time zone |
|
|
||||||
,") | text |
|
|
||||||
Indexes:
|
|
||||||
"cidx_only_ckey" btree (col2, ","")") CLUSTER
|
|
||||||
|
|
||||||
\d tbl_only_pkey
|
|
||||||
Table "public.tbl_only_pkey"
|
|
||||||
Column | Type | Modifiers
|
|
||||||
--------+---------+-----------
|
|
||||||
col1 | integer | not null
|
|
||||||
,") | text |
|
|
||||||
Indexes:
|
|
||||||
"tbl_only_pkey_pkey" PRIMARY KEY, btree (col1)
|
|
||||||
|
|
||||||
\d tbl_with_dropped_column
|
|
||||||
Table "public.tbl_with_dropped_column"
|
|
||||||
Column | Type | Modifiers
|
|
||||||
--------+---------+-----------
|
|
||||||
c1 | text |
|
|
||||||
id | integer | not null
|
|
||||||
c2 | text |
|
|
||||||
c3 | text |
|
|
||||||
Indexes:
|
|
||||||
"tbl_with_dropped_column_pkey" PRIMARY KEY, btree (id) WITH (fillfactor=75) CLUSTER
|
|
||||||
"idx_c1c2" btree (c1, c2) WITH (fillfactor=75)
|
|
||||||
"idx_c2c1" btree (c2, c1)
|
|
||||||
|
|
||||||
\d tbl_with_dropped_toast
|
|
||||||
Table "public.tbl_with_dropped_toast"
|
|
||||||
Column | Type | Modifiers
|
|
||||||
--------+---------+-----------
|
|
||||||
i | integer | not null
|
|
||||||
j | integer | not null
|
|
||||||
Indexes:
|
|
||||||
"tbl_with_dropped_toast_pkey" PRIMARY KEY, btree (i, j) CLUSTER
|
|
||||||
|
|
||||||
\d tbl_idxopts
|
|
||||||
Table "public.tbl_idxopts"
|
|
||||||
Column | Type | Modifiers
|
|
||||||
--------+---------+-----------
|
|
||||||
i | integer | not null
|
|
||||||
t | text |
|
|
||||||
Indexes:
|
|
||||||
"tbl_idxopts_pkey" PRIMARY KEY, btree (i)
|
|
||||||
"idxopts_t" btree (t DESC NULLS LAST) WHERE t <> 'aaa'::text
|
|
||||||
|
|
||||||
SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster;
|
|
||||||
col1 | to_char | ,")
|
|
||||||
------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
||||||
2 | 2008-01-01 00:00:00 | king
|
|
||||||
5 | 2008-01-01 00:30:00 | 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372352885092648612494977154218334204285686060146824720771435854874155657069677653720226485447015858801620758474922657226002085584466521458398893944370926591800311388246468157082630100594858704003186480342194897278290641045072636881313739855256117322040245091227700226941127573627280495738108967504018369868368450725799364729060762996941380475654823728997180326802474420629269124859052181004459842150591120249441341728531478105803603371077309182869314710171111683916581726889419758716582152128229518488471.732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248575675626141415406703029969945094998952478811655512094373648528093231902305582067974820101084674923265015312343266903322886650672254668921837971227047131660367861588019049986537379859389467650347506576050756618348129606100947602187190325083145829523959832997789824508288714463832917347224163984587855397667958063818353666110843173780894378316102088305524901670023520711144288695990956365797087168498072899493296484283020786408603988738697537582317317831395992983007838702877053913369563312103707264019249106768231199288375641141422016742752102372994270831059898459475987664288897796147837958390228854852903576033852808064381972344661059689722872865264153822664698420021195484155278441181286534507035191650016689294415480846071277143999762926834629577438361895110127148638746976545982451788550975379013880664961911962222957110555242923723192197738262561631468842032853716682938649611917049738836395495938
|
|
||||||
3 | 2008-03-04 12:00:00 | joker
|
|
||||||
4 | 2008-03-05 15:00:00 | queen
|
|
||||||
1 | 2008-12-31 10:00:00 | admin
|
|
||||||
(5 rows)
|
|
||||||
|
|
||||||
SELECT * FROM tbl_only_ckey ORDER BY 1;
|
|
||||||
col1 | col2 | ,")
|
|
||||||
------+--------------------------+-----
|
|
||||||
1 | Tue Jan 01 00:00:00 2008 | abc
|
|
||||||
2 | Fri Feb 01 00:00:00 2008 | def
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SELECT * FROM tbl_only_pkey ORDER BY 1;
|
|
||||||
col1 | ,")
|
|
||||||
------+-----
|
|
||||||
1 | abc
|
|
||||||
2 | def
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SELECT * FROM tbl_gistkey ORDER BY 1;
|
|
||||||
id | c
|
|
||||||
----+-----------
|
|
||||||
1 | <(1,2),3>
|
|
||||||
2 | <(4,5),6>
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SET enable_seqscan = on;
|
|
||||||
SET enable_indexscan = off;
|
|
||||||
SELECT * FROM tbl_with_dropped_column;
|
|
||||||
c1 | id | c2 | c3
|
|
||||||
----+----+----+----
|
|
||||||
c1 | 1 | c2 |
|
|
||||||
c1 | 2 | c2 |
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SELECT * FROM view_for_dropped_column;
|
|
||||||
c1 | id | c2 | c3
|
|
||||||
----+----+----+----
|
|
||||||
c1 | 1 | c2 |
|
|
||||||
c1 | 2 | c2 |
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SELECT * FROM tbl_with_dropped_toast;
|
|
||||||
i | j
|
|
||||||
---+----
|
|
||||||
1 | 10
|
|
||||||
2 | 20
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SET enable_seqscan = off;
|
|
||||||
SET enable_indexscan = on;
|
|
||||||
SELECT * FROM tbl_with_dropped_column;
|
|
||||||
c1 | id | c2 | c3
|
|
||||||
----+----+----+----
|
|
||||||
c1 | 1 | c2 |
|
|
||||||
c1 | 2 | c2 |
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SELECT * FROM view_for_dropped_column;
|
|
||||||
c1 | id | c2 | c3
|
|
||||||
----+----+----+----
|
|
||||||
c1 | 1 | c2 |
|
|
||||||
c1 | 2 | c2 |
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SELECT * FROM tbl_with_dropped_toast;
|
|
||||||
i | j
|
|
||||||
---+----
|
|
||||||
1 | 10
|
|
||||||
2 | 20
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
RESET enable_seqscan;
|
|
||||||
RESET enable_indexscan;
|
|
||||||
--
|
|
||||||
-- check broken links or orphan toast relations
|
|
||||||
--
|
|
||||||
SELECT oid, relname
|
|
||||||
FROM pg_class
|
|
||||||
WHERE relkind = 't'
|
|
||||||
AND oid NOT IN (SELECT reltoastrelid FROM pg_class WHERE relkind = 'r');
|
|
||||||
oid | relname
|
|
||||||
-----+---------
|
|
||||||
(0 rows)
|
|
||||||
|
|
||||||
SELECT oid, relname
|
|
||||||
FROM pg_class
|
|
||||||
WHERE relkind = 'r'
|
|
||||||
AND reltoastrelid <> 0
|
|
||||||
AND reltoastrelid NOT IN (SELECT oid FROM pg_class WHERE relkind = 't');
|
|
||||||
oid | relname
|
|
||||||
-----+---------
|
|
||||||
(0 rows)
|
|
||||||
|
|
||||||
--
|
|
||||||
-- NOT NULL UNIQUE
|
|
||||||
--
|
|
||||||
CREATE TABLE tbl_nn (col1 int NOT NULL, col2 int NOT NULL);
|
|
||||||
CREATE TABLE tbl_uk (col1 int NOT NULL, col2 int , UNIQUE(col1, col2));
|
|
||||||
CREATE TABLE tbl_nn_uk (col1 int NOT NULL, col2 int NOT NULL, UNIQUE(col1, col2));
|
|
||||||
CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(col1, col2), UNIQUE(col2, col1));
|
|
||||||
CREATE TABLE tbl_nn_puk (col1 int NOT NULL, col2 int NOT NULL);
|
|
||||||
CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10;
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_nn
|
|
||||||
WARNING: relation "tbl_nn" must have a primary key or not-null unique keys
|
|
||||||
-- => WARNING
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_uk
|
|
||||||
WARNING: relation "tbl_uk" must have a primary key or not-null unique keys
|
|
||||||
-- => WARNING
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_nn_uk
|
|
||||||
INFO: repacking table "tbl_nn_uk"
|
|
||||||
-- => OK
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk
|
|
||||||
INFO: repacking table "tbl_pk_uk"
|
|
||||||
-- => OK
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk --only-indexes
|
|
||||||
INFO: repacking indexes of "tbl_pk_uk"
|
|
||||||
INFO: repacking index "public"."tbl_pk_uk_col2_col1_key"
|
|
||||||
INFO: repacking index "public"."tbl_pk_uk_pkey"
|
|
||||||
-- => OK
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_nn_puk
|
|
||||||
WARNING: relation "tbl_nn_puk" must have a primary key or not-null unique keys
|
|
||||||
-- => WARNING
|
|
||||||
--
|
|
||||||
-- Triggers handling
|
|
||||||
--
|
|
||||||
CREATE FUNCTION trgtest() RETURNS trigger AS
|
|
||||||
$$BEGIN RETURN NEW; END$$
|
|
||||||
LANGUAGE plpgsql;
|
|
||||||
CREATE TABLE trg1 (id integer PRIMARY KEY);
|
|
||||||
CREATE TRIGGER z_repack_triggeq BEFORE UPDATE ON trg1 FOR EACH ROW EXECUTE PROCEDURE trgtest();
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=trg1
|
|
||||||
INFO: repacking table "trg1"
|
|
||||||
CREATE TABLE trg2 (id integer PRIMARY KEY);
|
|
||||||
CREATE TRIGGER z_repack_trigger BEFORE UPDATE ON trg2 FOR EACH ROW EXECUTE PROCEDURE trgtest();
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=trg2
|
|
||||||
INFO: repacking table "trg2"
|
|
||||||
WARNING: the table "trg2" already has a trigger called "z_repack_trigger"
|
|
||||||
DETAIL: The trigger was probably installed during a previous attempt to run pg_repack on the table which was interrupted and for some reason failed to clean up the temporary objects. Please drop the trigger or drop and recreate the pg_repack extension altogether to remove all the temporary objects left over.
|
|
||||||
CREATE TABLE trg3 (id integer PRIMARY KEY);
|
|
||||||
CREATE TRIGGER z_repack_trigges BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest();
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=trg3
|
|
||||||
INFO: repacking table "trg3"
|
|
||||||
WARNING: trigger "z_repack_trigges" conflicting on table "trg3"
|
|
||||||
DETAIL: The trigger "z_repack_trigger" must be the last of the BEFORE triggers to fire on the table (triggers fire in alphabetical order). Please rename the trigger so that it sorts before "z_repack_trigger": you can use "ALTER TRIGGER z_repack_trigges ON trg3 RENAME TO newname".
|
|
||||||
CREATE TABLE trg4 (id integer PRIMARY KEY);
|
|
||||||
CREATE TRIGGER zzzzzz AFTER UPDATE ON trg4 FOR EACH ROW EXECUTE PROCEDURE trgtest();
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=trg4
|
|
||||||
INFO: repacking table "trg4"
|
|
||||||
--
|
|
||||||
-- Dry run
|
|
||||||
--
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --dry-run
|
|
||||||
INFO: Dry run enabled, not executing repack
|
|
||||||
INFO: repacking table "tbl_cluster"
|
|
||||||
-- Test --schema
|
|
||||||
--
|
|
||||||
CREATE SCHEMA test_schema1;
|
|
||||||
CREATE TABLE test_schema1.tbl1 (id INTEGER PRIMARY KEY);
|
|
||||||
CREATE TABLE test_schema1.tbl2 (id INTEGER PRIMARY KEY);
|
|
||||||
CREATE SCHEMA test_schema2;
|
|
||||||
CREATE TABLE test_schema2.tbl1 (id INTEGER PRIMARY KEY);
|
|
||||||
CREATE TABLE test_schema2.tbl2 (id INTEGER PRIMARY KEY);
|
|
||||||
-- => OK
|
|
||||||
\! pg_repack --dbname=contrib_regression --schema=test_schema1
|
|
||||||
INFO: repacking table "test_schema1.tbl1"
|
|
||||||
INFO: repacking table "test_schema1.tbl2"
|
|
||||||
-- => OK
|
|
||||||
\! pg_repack --dbname=contrib_regression --schema=test_schema1 --schema=test_schema2
|
|
||||||
INFO: repacking table "test_schema1.tbl1"
|
|
||||||
INFO: repacking table "test_schema1.tbl2"
|
|
||||||
INFO: repacking table "test_schema2.tbl1"
|
|
||||||
INFO: repacking table "test_schema2.tbl2"
|
|
||||||
-- => ERROR
|
|
||||||
\! pg_repack --dbname=contrib_regression --schema=test_schema1 --table=tbl1
|
|
||||||
ERROR: cannot repack specific table(s) in schema, use schema.table notation instead
|
|
||||||
-- => ERROR
|
|
||||||
\! pg_repack --dbname=contrib_regression --all --schema=test_schema1
|
|
||||||
ERROR: cannot repack specific schema(s) in all databases
|
|
@ -1,482 +0,0 @@
|
|||||||
SET client_min_messages = warning;
|
|
||||||
--
|
|
||||||
-- create table.
|
|
||||||
--
|
|
||||||
CREATE TABLE tbl_cluster (
|
|
||||||
col1 int,
|
|
||||||
"time" timestamp,
|
|
||||||
","")" text,
|
|
||||||
PRIMARY KEY (","")", col1) WITH (fillfactor = 75)
|
|
||||||
) WITH (fillfactor = 70);
|
|
||||||
CREATE INDEX ","") cluster" ON tbl_cluster ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor = 75);
|
|
||||||
ALTER TABLE tbl_cluster CLUSTER ON ","") cluster";
|
|
||||||
CREATE TABLE tbl_only_pkey (
|
|
||||||
col1 int PRIMARY KEY,
|
|
||||||
","")" text
|
|
||||||
);
|
|
||||||
CREATE TABLE tbl_only_ckey (
|
|
||||||
col1 int,
|
|
||||||
col2 timestamp,
|
|
||||||
","")" text
|
|
||||||
) WITH (fillfactor = 70);
|
|
||||||
CREATE INDEX cidx_only_ckey ON tbl_only_ckey (col2, ","")");
|
|
||||||
ALTER TABLE tbl_only_ckey CLUSTER ON cidx_only_ckey;
|
|
||||||
CREATE TABLE tbl_gistkey (
|
|
||||||
id integer PRIMARY KEY,
|
|
||||||
c circle
|
|
||||||
);
|
|
||||||
CREATE INDEX cidx_circle ON tbl_gistkey USING gist (c);
|
|
||||||
ALTER TABLE tbl_gistkey CLUSTER ON cidx_circle;
|
|
||||||
CREATE TABLE tbl_with_dropped_column (
|
|
||||||
d1 text,
|
|
||||||
c1 text,
|
|
||||||
id integer PRIMARY KEY,
|
|
||||||
d2 text,
|
|
||||||
c2 text,
|
|
||||||
d3 text
|
|
||||||
);
|
|
||||||
ALTER INDEX tbl_with_dropped_column_pkey SET (fillfactor = 75);
|
|
||||||
ALTER TABLE tbl_with_dropped_column CLUSTER ON tbl_with_dropped_column_pkey;
|
|
||||||
CREATE INDEX idx_c1c2 ON tbl_with_dropped_column (c1, c2) WITH (fillfactor = 75);
|
|
||||||
CREATE INDEX idx_c2c1 ON tbl_with_dropped_column (c2, c1);
|
|
||||||
CREATE TABLE tbl_with_dropped_toast (
|
|
||||||
i integer,
|
|
||||||
j integer,
|
|
||||||
t text,
|
|
||||||
PRIMARY KEY (i, j)
|
|
||||||
);
|
|
||||||
ALTER TABLE tbl_with_dropped_toast CLUSTER ON tbl_with_dropped_toast_pkey;
|
|
||||||
CREATE TABLE tbl_badindex (
|
|
||||||
id integer PRIMARY KEY,
|
|
||||||
n integer
|
|
||||||
);
|
|
||||||
CREATE TABLE tbl_idxopts (
|
|
||||||
i integer PRIMARY KEY,
|
|
||||||
t text
|
|
||||||
);
|
|
||||||
CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa');
|
|
||||||
--
|
|
||||||
-- insert data
|
|
||||||
--
|
|
||||||
INSERT INTO tbl_cluster VALUES(1, '2008-12-31 10:00:00', 'admin');
|
|
||||||
INSERT INTO tbl_cluster VALUES(2, '2008-01-01 00:00:00', 'king');
|
|
||||||
INSERT INTO tbl_cluster VALUES(3, '2008-03-04 12:00:00', 'joker');
|
|
||||||
INSERT INTO tbl_cluster VALUES(4, '2008-03-05 15:00:00', 'queen');
|
|
||||||
INSERT INTO tbl_cluster VALUES(5, '2008-01-01 00:30:00', sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text);
|
|
||||||
INSERT INTO tbl_only_pkey VALUES(1, 'abc');
|
|
||||||
INSERT INTO tbl_only_pkey VALUES(2, 'def');
|
|
||||||
INSERT INTO tbl_only_ckey VALUES(1, '2008-01-01 00:00:00', 'abc');
|
|
||||||
INSERT INTO tbl_only_ckey VALUES(2, '2008-02-01 00:00:00', 'def');
|
|
||||||
INSERT INTO tbl_gistkey VALUES(1, '<(1,2),3>');
|
|
||||||
INSERT INTO tbl_gistkey VALUES(2, '<(4,5),6>');
|
|
||||||
INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 2, 'd2', 'c2', 'd3');
|
|
||||||
INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 1, 'd2', 'c2', 'd3');
|
|
||||||
ALTER TABLE tbl_with_dropped_column DROP COLUMN d1;
|
|
||||||
ALTER TABLE tbl_with_dropped_column DROP COLUMN d2;
|
|
||||||
ALTER TABLE tbl_with_dropped_column DROP COLUMN d3;
|
|
||||||
ALTER TABLE tbl_with_dropped_column ADD COLUMN c3 text;
|
|
||||||
CREATE VIEW view_for_dropped_column AS
|
|
||||||
SELECT * FROM tbl_with_dropped_column;
|
|
||||||
INSERT INTO tbl_with_dropped_toast VALUES(1, 10, 'abc');
|
|
||||||
INSERT INTO tbl_with_dropped_toast VALUES(2, 20, sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text);
|
|
||||||
ALTER TABLE tbl_with_dropped_toast DROP COLUMN t;
|
|
||||||
INSERT INTO tbl_badindex VALUES(1, 10);
|
|
||||||
INSERT INTO tbl_badindex VALUES(2, 10);
|
|
||||||
-- This will fail. Silence the message as it's different across PG versions.
|
|
||||||
SET client_min_messages = fatal;
|
|
||||||
CREATE UNIQUE INDEX CONCURRENTLY idx_badindex_n ON tbl_badindex (n);
|
|
||||||
SET client_min_messages = warning;
|
|
||||||
INSERT INTO tbl_idxopts VALUES (0, 'abc'), (1, 'aaa'), (2, NULL), (3, 'bbb');
|
|
||||||
--
|
|
||||||
-- before
|
|
||||||
--
|
|
||||||
SELECT * FROM tbl_with_dropped_column;
|
|
||||||
c1 | id | c2 | c3
|
|
||||||
----+----+----+----
|
|
||||||
c1 | 2 | c2 |
|
|
||||||
c1 | 1 | c2 |
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SELECT * FROM view_for_dropped_column;
|
|
||||||
c1 | id | c2 | c3
|
|
||||||
----+----+----+----
|
|
||||||
c1 | 2 | c2 |
|
|
||||||
c1 | 1 | c2 |
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SELECT * FROM tbl_with_dropped_toast;
|
|
||||||
i | j
|
|
||||||
---+----
|
|
||||||
1 | 10
|
|
||||||
2 | 20
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
--
|
|
||||||
-- do repack
|
|
||||||
--
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_cluster
|
|
||||||
INFO: repacking table "tbl_cluster"
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_badindex
|
|
||||||
INFO: repacking table "tbl_badindex"
|
|
||||||
WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n)
|
|
||||||
\! pg_repack --dbname=contrib_regression
|
|
||||||
INFO: repacking table "tbl_cluster"
|
|
||||||
INFO: repacking table "tbl_only_pkey"
|
|
||||||
INFO: repacking table "tbl_gistkey"
|
|
||||||
INFO: repacking table "tbl_with_dropped_column"
|
|
||||||
INFO: repacking table "tbl_with_dropped_toast"
|
|
||||||
INFO: repacking table "tbl_badindex"
|
|
||||||
WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n)
|
|
||||||
INFO: repacking table "tbl_idxopts"
|
|
||||||
--
|
|
||||||
-- after
|
|
||||||
--
|
|
||||||
\d tbl_cluster
|
|
||||||
Table "public.tbl_cluster"
|
|
||||||
Column | Type | Modifiers
|
|
||||||
--------+-----------------------------+-----------
|
|
||||||
col1 | integer | not null
|
|
||||||
time | timestamp without time zone |
|
|
||||||
,") | text | not null
|
|
||||||
Indexes:
|
|
||||||
"tbl_cluster_pkey" PRIMARY KEY, btree (","")", col1) WITH (fillfactor='75')
|
|
||||||
",") cluster" btree ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor='75') CLUSTER
|
|
||||||
|
|
||||||
\d tbl_gistkey
|
|
||||||
Table "public.tbl_gistkey"
|
|
||||||
Column | Type | Modifiers
|
|
||||||
--------+---------+-----------
|
|
||||||
id | integer | not null
|
|
||||||
c | circle |
|
|
||||||
Indexes:
|
|
||||||
"tbl_gistkey_pkey" PRIMARY KEY, btree (id)
|
|
||||||
"cidx_circle" gist (c) CLUSTER
|
|
||||||
|
|
||||||
\d tbl_only_ckey
|
|
||||||
Table "public.tbl_only_ckey"
|
|
||||||
Column | Type | Modifiers
|
|
||||||
--------+-----------------------------+-----------
|
|
||||||
col1 | integer |
|
|
||||||
col2 | timestamp without time zone |
|
|
||||||
,") | text |
|
|
||||||
Indexes:
|
|
||||||
"cidx_only_ckey" btree (col2, ","")") CLUSTER
|
|
||||||
|
|
||||||
\d tbl_only_pkey
|
|
||||||
Table "public.tbl_only_pkey"
|
|
||||||
Column | Type | Modifiers
|
|
||||||
--------+---------+-----------
|
|
||||||
col1 | integer | not null
|
|
||||||
,") | text |
|
|
||||||
Indexes:
|
|
||||||
"tbl_only_pkey_pkey" PRIMARY KEY, btree (col1)
|
|
||||||
|
|
||||||
\d tbl_with_dropped_column
|
|
||||||
Table "public.tbl_with_dropped_column"
|
|
||||||
Column | Type | Modifiers
|
|
||||||
--------+---------+-----------
|
|
||||||
c1 | text |
|
|
||||||
id | integer | not null
|
|
||||||
c2 | text |
|
|
||||||
c3 | text |
|
|
||||||
Indexes:
|
|
||||||
"tbl_with_dropped_column_pkey" PRIMARY KEY, btree (id) WITH (fillfactor='75') CLUSTER
|
|
||||||
"idx_c1c2" btree (c1, c2) WITH (fillfactor='75')
|
|
||||||
"idx_c2c1" btree (c2, c1)
|
|
||||||
|
|
||||||
\d tbl_with_dropped_toast
|
|
||||||
Table "public.tbl_with_dropped_toast"
|
|
||||||
Column | Type | Modifiers
|
|
||||||
--------+---------+-----------
|
|
||||||
i | integer | not null
|
|
||||||
j | integer | not null
|
|
||||||
Indexes:
|
|
||||||
"tbl_with_dropped_toast_pkey" PRIMARY KEY, btree (i, j) CLUSTER
|
|
||||||
|
|
||||||
\d tbl_idxopts
|
|
||||||
Table "public.tbl_idxopts"
|
|
||||||
Column | Type | Modifiers
|
|
||||||
--------+---------+-----------
|
|
||||||
i | integer | not null
|
|
||||||
t | text |
|
|
||||||
Indexes:
|
|
||||||
"tbl_idxopts_pkey" PRIMARY KEY, btree (i)
|
|
||||||
"idxopts_t" btree (t DESC NULLS LAST) WHERE t <> 'aaa'::text
|
|
||||||
|
|
||||||
SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster;
|
|
||||||
col1 | to_char | ,")
|
|
||||||
------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
||||||
2 | 2008-01-01 00:00:00 | king
|
|
||||||
5 | 2008-01-01 00:30:00 | 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372352885092648612494977154218334204285686060146824720771435854874155657069677653720226485447015858801620758474922657226002085584466521458398893944370926591800311388246468157082630100594858704003186480342194897278290641045072636881313739855256117322040245091227700226941127573627280495738108967504018369868368450725799364729060762996941380475654823728997180326802474420629269124859052181004459842150591120249441341728531478105803603371077309182869314710171111683916581726889419758716582152128229518488471.732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248575675626141415406703029969945094998952478811655512094373648528093231902305582067974820101084674923265015312343266903322886650672254668921837971227047131660367861588019049986537379859389467650347506576050756618348129606100947602187190325083145829523959832997789824508288714463832917347224163984587855397667958063818353666110843173780894378316102088305524901670023520711144288695990956365797087168498072899493296484283020786408603988738697537582317317831395992983007838702877053913369563312103707264019249106768231199288375641141422016742752102372994270831059898459475987664288897796147837958390228854852903576033852808064381972344661059689722872865264153822664698420021195484155278441181286534507035191650016689294415480846071277143999762926834629577438361895110127148638746976545982451788550975379013880664961911962222957110555242923723192197738262561631468842032853716682938649611917049738836395495938
|
|
||||||
3 | 2008-03-04 12:00:00 | joker
|
|
||||||
4 | 2008-03-05 15:00:00 | queen
|
|
||||||
1 | 2008-12-31 10:00:00 | admin
|
|
||||||
(5 rows)
|
|
||||||
|
|
||||||
SELECT * FROM tbl_only_ckey ORDER BY 1;
|
|
||||||
col1 | col2 | ,")
|
|
||||||
------+--------------------------+-----
|
|
||||||
1 | Tue Jan 01 00:00:00 2008 | abc
|
|
||||||
2 | Fri Feb 01 00:00:00 2008 | def
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SELECT * FROM tbl_only_pkey ORDER BY 1;
|
|
||||||
col1 | ,")
|
|
||||||
------+-----
|
|
||||||
1 | abc
|
|
||||||
2 | def
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SELECT * FROM tbl_gistkey ORDER BY 1;
|
|
||||||
id | c
|
|
||||||
----+-----------
|
|
||||||
1 | <(1,2),3>
|
|
||||||
2 | <(4,5),6>
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SET enable_seqscan = on;
|
|
||||||
SET enable_indexscan = off;
|
|
||||||
SELECT * FROM tbl_with_dropped_column;
|
|
||||||
c1 | id | c2 | c3
|
|
||||||
----+----+----+----
|
|
||||||
c1 | 1 | c2 |
|
|
||||||
c1 | 2 | c2 |
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SELECT * FROM view_for_dropped_column;
|
|
||||||
c1 | id | c2 | c3
|
|
||||||
----+----+----+----
|
|
||||||
c1 | 1 | c2 |
|
|
||||||
c1 | 2 | c2 |
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SELECT * FROM tbl_with_dropped_toast;
|
|
||||||
i | j
|
|
||||||
---+----
|
|
||||||
1 | 10
|
|
||||||
2 | 20
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SET enable_seqscan = off;
|
|
||||||
SET enable_indexscan = on;
|
|
||||||
SELECT * FROM tbl_with_dropped_column;
|
|
||||||
c1 | id | c2 | c3
|
|
||||||
----+----+----+----
|
|
||||||
c1 | 1 | c2 |
|
|
||||||
c1 | 2 | c2 |
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SELECT * FROM view_for_dropped_column;
|
|
||||||
c1 | id | c2 | c3
|
|
||||||
----+----+----+----
|
|
||||||
c1 | 1 | c2 |
|
|
||||||
c1 | 2 | c2 |
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
SELECT * FROM tbl_with_dropped_toast;
|
|
||||||
i | j
|
|
||||||
---+----
|
|
||||||
1 | 10
|
|
||||||
2 | 20
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
RESET enable_seqscan;
|
|
||||||
RESET enable_indexscan;
|
|
||||||
--
|
|
||||||
-- check broken links or orphan toast relations
|
|
||||||
--
|
|
||||||
SELECT oid, relname
|
|
||||||
FROM pg_class
|
|
||||||
WHERE relkind = 't'
|
|
||||||
AND oid NOT IN (SELECT reltoastrelid FROM pg_class WHERE relkind = 'r');
|
|
||||||
oid | relname
|
|
||||||
-----+---------
|
|
||||||
(0 rows)
|
|
||||||
|
|
||||||
SELECT oid, relname
|
|
||||||
FROM pg_class
|
|
||||||
WHERE relkind = 'r'
|
|
||||||
AND reltoastrelid <> 0
|
|
||||||
AND reltoastrelid NOT IN (SELECT oid FROM pg_class WHERE relkind = 't');
|
|
||||||
oid | relname
|
|
||||||
-----+---------
|
|
||||||
(0 rows)
|
|
||||||
|
|
||||||
--
|
|
||||||
-- NOT NULL UNIQUE
|
|
||||||
--
|
|
||||||
CREATE TABLE tbl_nn (col1 int NOT NULL, col2 int NOT NULL);
|
|
||||||
CREATE TABLE tbl_uk (col1 int NOT NULL, col2 int , UNIQUE(col1, col2));
|
|
||||||
CREATE TABLE tbl_nn_uk (col1 int NOT NULL, col2 int NOT NULL, UNIQUE(col1, col2));
|
|
||||||
CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(col1, col2), UNIQUE(col2, col1));
|
|
||||||
CREATE TABLE tbl_nn_puk (col1 int NOT NULL, col2 int NOT NULL);
|
|
||||||
CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10;
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_nn
|
|
||||||
WARNING: relation "tbl_nn" must have a primary key or not-null unique keys
|
|
||||||
-- => WARNING
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_uk
|
|
||||||
WARNING: relation "tbl_uk" must have a primary key or not-null unique keys
|
|
||||||
-- => WARNING
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_nn_uk
|
|
||||||
INFO: repacking table "tbl_nn_uk"
|
|
||||||
-- => OK
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk
|
|
||||||
INFO: repacking table "tbl_pk_uk"
|
|
||||||
-- => OK
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk --only-indexes
|
|
||||||
INFO: repacking indexes of "tbl_pk_uk"
|
|
||||||
INFO: repacking index "public"."tbl_pk_uk_col2_col1_key"
|
|
||||||
INFO: repacking index "public"."tbl_pk_uk_pkey"
|
|
||||||
-- => OK
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_nn_puk
|
|
||||||
WARNING: relation "tbl_nn_puk" must have a primary key or not-null unique keys
|
|
||||||
-- => WARNING
|
|
||||||
--
|
|
||||||
-- Triggers handling
|
|
||||||
--
|
|
||||||
CREATE FUNCTION trgtest() RETURNS trigger AS
|
|
||||||
$$BEGIN RETURN NEW; END$$
|
|
||||||
LANGUAGE plpgsql;
|
|
||||||
CREATE TABLE trg1 (id integer PRIMARY KEY);
|
|
||||||
CREATE TRIGGER repack_trigger_1 AFTER UPDATE ON trg1 FOR EACH ROW EXECUTE PROCEDURE trgtest();
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=trg1
|
|
||||||
INFO: repacking table "trg1"
|
|
||||||
CREATE TABLE trg2 (id integer PRIMARY KEY);
|
|
||||||
CREATE TRIGGER repack_trigger AFTER UPDATE ON trg2 FOR EACH ROW EXECUTE PROCEDURE trgtest();
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=trg2
|
|
||||||
INFO: repacking table "trg2"
|
|
||||||
WARNING: the table "trg2" already has a trigger called "repack_trigger"
|
|
||||||
DETAIL: The trigger was probably installed during a previous attempt to run pg_repack on the table which was interrupted and for some reason failed to clean up the temporary objects. Please drop the trigger or drop and recreate the pg_repack extension altogether to remove all the temporary objects left over.
|
|
||||||
CREATE TABLE trg3 (id integer PRIMARY KEY);
|
|
||||||
CREATE TRIGGER repack_trigger_1 BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest();
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=trg3
|
|
||||||
INFO: repacking table "trg3"
|
|
||||||
--
|
|
||||||
-- Dry run
|
|
||||||
--
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --dry-run
|
|
||||||
INFO: Dry run enabled, not executing repack
|
|
||||||
INFO: repacking table "tbl_cluster"
|
|
||||||
-- Test --schema
|
|
||||||
--
|
|
||||||
CREATE SCHEMA test_schema1;
|
|
||||||
CREATE TABLE test_schema1.tbl1 (id INTEGER PRIMARY KEY);
|
|
||||||
CREATE TABLE test_schema1.tbl2 (id INTEGER PRIMARY KEY);
|
|
||||||
CREATE SCHEMA test_schema2;
|
|
||||||
CREATE TABLE test_schema2.tbl1 (id INTEGER PRIMARY KEY);
|
|
||||||
CREATE TABLE test_schema2.tbl2 (id INTEGER PRIMARY KEY);
|
|
||||||
-- => OK
|
|
||||||
\! pg_repack --dbname=contrib_regression --schema=test_schema1
|
|
||||||
INFO: repacking table "test_schema1.tbl1"
|
|
||||||
INFO: repacking table "test_schema1.tbl2"
|
|
||||||
-- => OK
|
|
||||||
\! pg_repack --dbname=contrib_regression --schema=test_schema1 --schema=test_schema2
|
|
||||||
INFO: repacking table "test_schema1.tbl1"
|
|
||||||
INFO: repacking table "test_schema1.tbl2"
|
|
||||||
INFO: repacking table "test_schema2.tbl1"
|
|
||||||
INFO: repacking table "test_schema2.tbl2"
|
|
||||||
-- => ERROR
|
|
||||||
\! pg_repack --dbname=contrib_regression --schema=test_schema1 --table=tbl1
|
|
||||||
ERROR: cannot repack specific table(s) in schema, use schema.table notation instead
|
|
||||||
-- => ERROR
|
|
||||||
\! pg_repack --dbname=contrib_regression --all --schema=test_schema1
|
|
||||||
ERROR: cannot repack specific schema(s) in all databases
|
|
||||||
--
|
|
||||||
-- don't kill backend
|
|
||||||
--
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-kill-backend
|
|
||||||
INFO: repacking table "tbl_cluster"
|
|
||||||
--
|
|
||||||
-- no superuser check
|
|
||||||
--
|
|
||||||
DROP ROLE IF EXISTS nosuper;
|
|
||||||
CREATE ROLE nosuper WITH LOGIN;
|
|
||||||
-- => OK
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-superuser-check
|
|
||||||
INFO: repacking table "tbl_cluster"
|
|
||||||
-- => ERROR
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper
|
|
||||||
ERROR: pg_repack failed with error: You must be a superuser to use pg_repack
|
|
||||||
-- => ERROR
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper --no-superuser-check
|
|
||||||
ERROR: pg_repack failed with error: ERROR: permission denied for schema repack
|
|
||||||
DROP ROLE IF EXISTS nosuper;
|
|
||||||
--
|
|
||||||
-- exclude extension check
|
|
||||||
--
|
|
||||||
CREATE SCHEMA exclude_extension_schema;
|
|
||||||
CREATE TABLE exclude_extension_schema.tbl(val integer primary key);
|
|
||||||
-- => ERROR
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=dummy_table --exclude-extension=dummy_extension
|
|
||||||
ERROR: cannot specify --table (-t) and --exclude-extension (-C)
|
|
||||||
-- => ERROR
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=dummy_table --exclude-extension=dummy_extension -x
|
|
||||||
ERROR: cannot specify --only-indexes (-x) and --exclude-extension (-C)
|
|
||||||
-- => ERROR
|
|
||||||
\! pg_repack --dbname=contrib_regression --index=dummy_index --exclude-extension=dummy_extension
|
|
||||||
ERROR: cannot specify --index (-i) and --exclude-extension (-C)
|
|
||||||
-- => OK
|
|
||||||
\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension
|
|
||||||
INFO: repacking table "exclude_extension_schema.tbl"
|
|
||||||
-- => OK
|
|
||||||
\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension --exclude-extension=dummy_extension
|
|
||||||
INFO: repacking table "exclude_extension_schema.tbl"
|
|
||||||
--
|
|
||||||
-- table inheritance check
|
|
||||||
--
|
|
||||||
CREATE TABLE parent_a(val integer primary key);
|
|
||||||
CREATE TABLE child_a_1(val integer primary key) INHERITS(parent_a);
|
|
||||||
CREATE TABLE child_a_2(val integer primary key) INHERITS(parent_a);
|
|
||||||
CREATE TABLE parent_b(val integer primary key);
|
|
||||||
CREATE TABLE child_b_1(val integer primary key) INHERITS(parent_b);
|
|
||||||
CREATE TABLE child_b_2(val integer primary key) INHERITS(parent_b);
|
|
||||||
-- => ERROR
|
|
||||||
\! pg_repack --dbname=contrib_regression --parent-table=dummy_table
|
|
||||||
ERROR: pg_repack failed with error: ERROR: relation "dummy_table" does not exist
|
|
||||||
-- => ERROR
|
|
||||||
\! pg_repack --dbname=contrib_regression --parent-table=dummy_index --index=dummy_index
|
|
||||||
ERROR: cannot specify --index (-i) and --parent-table (-I)
|
|
||||||
-- => ERROR
|
|
||||||
\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --schema=dummy_schema
|
|
||||||
ERROR: cannot repack specific table(s) in schema, use schema.table notation instead
|
|
||||||
-- => ERROR
|
|
||||||
\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --all
|
|
||||||
ERROR: cannot repack specific table(s) in all databases
|
|
||||||
-- => OK
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b
|
|
||||||
INFO: repacking table "parent_a"
|
|
||||||
INFO: repacking table "parent_b"
|
|
||||||
INFO: repacking table "child_b_1"
|
|
||||||
INFO: repacking table "child_b_2"
|
|
||||||
-- => OK
|
|
||||||
\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b
|
|
||||||
INFO: repacking table "parent_a"
|
|
||||||
INFO: repacking table "child_a_1"
|
|
||||||
INFO: repacking table "child_a_2"
|
|
||||||
INFO: repacking table "parent_b"
|
|
||||||
INFO: repacking table "child_b_1"
|
|
||||||
INFO: repacking table "child_b_2"
|
|
||||||
-- => OK
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b --only-indexes
|
|
||||||
INFO: repacking indexes of "parent_a"
|
|
||||||
INFO: repacking index "public"."parent_a_pkey"
|
|
||||||
INFO: repacking indexes of "public.child_b_1"
|
|
||||||
INFO: repacking index "public"."child_b_1_pkey"
|
|
||||||
INFO: repacking indexes of "public.child_b_2"
|
|
||||||
INFO: repacking index "public"."child_b_2_pkey"
|
|
||||||
INFO: repacking indexes of "public.parent_b"
|
|
||||||
INFO: repacking index "public"."parent_b_pkey"
|
|
||||||
-- => OK
|
|
||||||
\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b --only-indexes
|
|
||||||
INFO: repacking indexes of "public.child_a_1"
|
|
||||||
INFO: repacking index "public"."child_a_1_pkey"
|
|
||||||
INFO: repacking indexes of "public.child_a_2"
|
|
||||||
INFO: repacking index "public"."child_a_2_pkey"
|
|
||||||
INFO: repacking indexes of "public.parent_a"
|
|
||||||
INFO: repacking index "public"."parent_a_pkey"
|
|
||||||
INFO: repacking indexes of "public.child_b_1"
|
|
||||||
INFO: repacking index "public"."child_b_1_pkey"
|
|
||||||
INFO: repacking indexes of "public.child_b_2"
|
|
||||||
INFO: repacking index "public"."child_b_2_pkey"
|
|
||||||
INFO: repacking indexes of "public.parent_b"
|
|
||||||
INFO: repacking index "public"."parent_b_pkey"
|
|
@ -23,11 +23,11 @@ SELECT regexp_replace(
|
|||||||
'_[0-9]+', '_OID', 'g')
|
'_[0-9]+', '_OID', 'g')
|
||||||
FROM pg_index i join pg_class c ON c.oid = indexrelid
|
FROM pg_index i join pg_class c ON c.oid = indexrelid
|
||||||
WHERE indrelid = 'testts1'::regclass ORDER BY relname;
|
WHERE indrelid = 'testts1'::regclass ORDER BY relname;
|
||||||
regexp_replace
|
regexp_replace
|
||||||
----------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------------
|
||||||
CREATE INDEX index_OID ON repack.table_OID USING btree (id) WHERE (id > 0)
|
CREATE INDEX index_OID ON repack.table_OID USING btree (id) TABLESPACE pg_default WHERE (id > 0)
|
||||||
CREATE UNIQUE INDEX index_OID ON repack.table_OID USING btree (id)
|
CREATE UNIQUE INDEX index_OID ON repack.table_OID USING btree (id) TABLESPACE pg_default
|
||||||
CREATE INDEX index_OID ON repack.table_OID USING btree (id) WITH (fillfactor=80)
|
CREATE INDEX index_OID ON repack.table_OID USING btree (id) WITH (fillfactor='80') TABLESPACE pg_default
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
SELECT regexp_replace(
|
SELECT regexp_replace(
|
||||||
@ -35,11 +35,11 @@ SELECT regexp_replace(
|
|||||||
'_[0-9]+', '_OID', 'g')
|
'_[0-9]+', '_OID', 'g')
|
||||||
FROM pg_index i join pg_class c ON c.oid = indexrelid
|
FROM pg_index i join pg_class c ON c.oid = indexrelid
|
||||||
WHERE indrelid = 'testts1'::regclass ORDER BY relname;
|
WHERE indrelid = 'testts1'::regclass ORDER BY relname;
|
||||||
regexp_replace
|
regexp_replace
|
||||||
-------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
CREATE INDEX index_OID ON repack.table_OID USING btree (id) TABLESPACE foo WHERE (id > 0)
|
CREATE INDEX index_OID ON repack.table_OID USING btree (id) TABLESPACE foo WHERE (id > 0)
|
||||||
CREATE UNIQUE INDEX index_OID ON repack.table_OID USING btree (id) TABLESPACE foo
|
CREATE UNIQUE INDEX index_OID ON repack.table_OID USING btree (id) TABLESPACE foo
|
||||||
CREATE INDEX index_OID ON repack.table_OID USING btree (id) WITH (fillfactor=80) TABLESPACE foo
|
CREATE INDEX index_OID ON repack.table_OID USING btree (id) WITH (fillfactor='80') TABLESPACE foo
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
SELECT regexp_replace(
|
SELECT regexp_replace(
|
||||||
@ -47,11 +47,11 @@ SELECT regexp_replace(
|
|||||||
'_[0-9]+', '_OID', 'g')
|
'_[0-9]+', '_OID', 'g')
|
||||||
FROM pg_index i join pg_class c ON c.oid = indexrelid
|
FROM pg_index i join pg_class c ON c.oid = indexrelid
|
||||||
WHERE indrelid = 'testts1'::regclass ORDER BY relname;
|
WHERE indrelid = 'testts1'::regclass ORDER BY relname;
|
||||||
regexp_replace
|
regexp_replace
|
||||||
--------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------------------------------
|
||||||
CREATE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) WHERE (id > 0)
|
CREATE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) TABLESPACE pg_default WHERE (id > 0)
|
||||||
CREATE UNIQUE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id)
|
CREATE UNIQUE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) TABLESPACE pg_default
|
||||||
CREATE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) WITH (fillfactor=80)
|
CREATE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) WITH (fillfactor='80') TABLESPACE pg_default
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
SELECT regexp_replace(
|
SELECT regexp_replace(
|
||||||
@ -59,11 +59,11 @@ SELECT regexp_replace(
|
|||||||
'_[0-9]+', '_OID', 'g')
|
'_[0-9]+', '_OID', 'g')
|
||||||
FROM pg_index i join pg_class c ON c.oid = indexrelid
|
FROM pg_index i join pg_class c ON c.oid = indexrelid
|
||||||
WHERE indrelid = 'testts1'::regclass ORDER BY relname;
|
WHERE indrelid = 'testts1'::regclass ORDER BY relname;
|
||||||
regexp_replace
|
regexp_replace
|
||||||
-----------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------
|
||||||
CREATE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) TABLESPACE foo WHERE (id > 0)
|
CREATE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) TABLESPACE foo WHERE (id > 0)
|
||||||
CREATE UNIQUE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) TABLESPACE foo
|
CREATE UNIQUE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) TABLESPACE foo
|
||||||
CREATE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) WITH (fillfactor=80) TABLESPACE foo
|
CREATE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) WITH (fillfactor='80') TABLESPACE foo
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
-- can move the tablespace from default
|
-- can move the tablespace from default
|
||||||
|
@ -1,234 +0,0 @@
|
|||||||
SET client_min_messages = warning;
|
|
||||||
--
|
|
||||||
-- Tablespace features tests
|
|
||||||
--
|
|
||||||
-- Note: in order to pass this test you must create a tablespace called 'testts'
|
|
||||||
--
|
|
||||||
SELECT spcname FROM pg_tablespace WHERE spcname = 'testts';
|
|
||||||
spcname
|
|
||||||
---------
|
|
||||||
testts
|
|
||||||
(1 row)
|
|
||||||
|
|
||||||
-- If the query above failed you must create the 'testts' tablespace;
|
|
||||||
CREATE TABLE testts1 (id serial primary key, data text);
|
|
||||||
CREATE INDEX testts1_partial_idx on testts1 (id) where (id > 0);
|
|
||||||
CREATE INDEX testts1_with_idx on testts1 (id) with (fillfactor=80);
|
|
||||||
INSERT INTO testts1 (data) values ('a');
|
|
||||||
INSERT INTO testts1 (data) values ('b');
|
|
||||||
INSERT INTO testts1 (data) values ('c');
|
|
||||||
-- check the indexes definitions
|
|
||||||
SELECT regexp_replace(
|
|
||||||
repack.repack_indexdef(indexrelid, 'testts1'::regclass, NULL, false),
|
|
||||||
'_[0-9]+', '_OID', 'g')
|
|
||||||
FROM pg_index i join pg_class c ON c.oid = indexrelid
|
|
||||||
WHERE indrelid = 'testts1'::regclass ORDER BY relname;
|
|
||||||
regexp_replace
|
|
||||||
----------------------------------------------------------------------------------------------------------
|
|
||||||
CREATE INDEX index_OID ON repack.table_OID USING btree (id) TABLESPACE pg_default WHERE (id > 0)
|
|
||||||
CREATE UNIQUE INDEX index_OID ON repack.table_OID USING btree (id) TABLESPACE pg_default
|
|
||||||
CREATE INDEX index_OID ON repack.table_OID USING btree (id) WITH (fillfactor='80') TABLESPACE pg_default
|
|
||||||
(3 rows)
|
|
||||||
|
|
||||||
SELECT regexp_replace(
|
|
||||||
repack.repack_indexdef(indexrelid, 'testts1'::regclass, 'foo', false),
|
|
||||||
'_[0-9]+', '_OID', 'g')
|
|
||||||
FROM pg_index i join pg_class c ON c.oid = indexrelid
|
|
||||||
WHERE indrelid = 'testts1'::regclass ORDER BY relname;
|
|
||||||
regexp_replace
|
|
||||||
---------------------------------------------------------------------------------------------------
|
|
||||||
CREATE INDEX index_OID ON repack.table_OID USING btree (id) TABLESPACE foo WHERE (id > 0)
|
|
||||||
CREATE UNIQUE INDEX index_OID ON repack.table_OID USING btree (id) TABLESPACE foo
|
|
||||||
CREATE INDEX index_OID ON repack.table_OID USING btree (id) WITH (fillfactor='80') TABLESPACE foo
|
|
||||||
(3 rows)
|
|
||||||
|
|
||||||
SELECT regexp_replace(
|
|
||||||
repack.repack_indexdef(indexrelid, 'testts1'::regclass, NULL, true),
|
|
||||||
'_[0-9]+', '_OID', 'g')
|
|
||||||
FROM pg_index i join pg_class c ON c.oid = indexrelid
|
|
||||||
WHERE indrelid = 'testts1'::regclass ORDER BY relname;
|
|
||||||
regexp_replace
|
|
||||||
--------------------------------------------------------------------------------------------------------------
|
|
||||||
CREATE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) TABLESPACE pg_default WHERE (id > 0)
|
|
||||||
CREATE UNIQUE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) TABLESPACE pg_default
|
|
||||||
CREATE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) WITH (fillfactor='80') TABLESPACE pg_default
|
|
||||||
(3 rows)
|
|
||||||
|
|
||||||
SELECT regexp_replace(
|
|
||||||
repack.repack_indexdef(indexrelid, 'testts1'::regclass, 'foo', true),
|
|
||||||
'_[0-9]+', '_OID', 'g')
|
|
||||||
FROM pg_index i join pg_class c ON c.oid = indexrelid
|
|
||||||
WHERE indrelid = 'testts1'::regclass ORDER BY relname;
|
|
||||||
regexp_replace
|
|
||||||
-------------------------------------------------------------------------------------------------------
|
|
||||||
CREATE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) TABLESPACE foo WHERE (id > 0)
|
|
||||||
CREATE UNIQUE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) TABLESPACE foo
|
|
||||||
CREATE INDEX CONCURRENTLY index_OID ON testts1 USING btree (id) WITH (fillfactor='80') TABLESPACE foo
|
|
||||||
(3 rows)
|
|
||||||
|
|
||||||
-- can move the tablespace from default
|
|
||||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts
|
|
||||||
INFO: repacking table "testts1"
|
|
||||||
SELECT relname, spcname
|
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
|
||||||
WHERE relname ~ '^testts1'
|
|
||||||
ORDER BY relname;
|
|
||||||
relname | spcname
|
|
||||||
---------+---------
|
|
||||||
testts1 | testts
|
|
||||||
(1 row)
|
|
||||||
|
|
||||||
SELECT * from testts1 order by id;
|
|
||||||
id | data
|
|
||||||
----+------
|
|
||||||
1 | a
|
|
||||||
2 | b
|
|
||||||
3 | c
|
|
||||||
(3 rows)
|
|
||||||
|
|
||||||
-- tablespace stays where it is
|
|
||||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1
|
|
||||||
INFO: repacking table "testts1"
|
|
||||||
SELECT relname, spcname
|
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
|
||||||
WHERE relname ~ '^testts1'
|
|
||||||
ORDER BY relname;
|
|
||||||
relname | spcname
|
|
||||||
---------+---------
|
|
||||||
testts1 | testts
|
|
||||||
(1 row)
|
|
||||||
|
|
||||||
-- can move the ts back to default
|
|
||||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 -s pg_default
|
|
||||||
INFO: repacking table "testts1"
|
|
||||||
SELECT relname, spcname
|
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
|
||||||
WHERE relname ~ '^testts1'
|
|
||||||
ORDER BY relname;
|
|
||||||
relname | spcname
|
|
||||||
---------+---------
|
|
||||||
(0 rows)
|
|
||||||
|
|
||||||
-- can move the table together with the indexes
|
|
||||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts --moveidx
|
|
||||||
INFO: repacking table "testts1"
|
|
||||||
SELECT relname, spcname
|
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
|
||||||
WHERE relname ~ '^testts1'
|
|
||||||
ORDER BY relname;
|
|
||||||
relname | spcname
|
|
||||||
---------------------+---------
|
|
||||||
testts1 | testts
|
|
||||||
testts1_partial_idx | testts
|
|
||||||
testts1_pkey | testts
|
|
||||||
testts1_with_idx | testts
|
|
||||||
(4 rows)
|
|
||||||
|
|
||||||
-- can't specify --moveidx without --tablespace
|
|
||||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --moveidx
|
|
||||||
ERROR: cannot specify --moveidx (-S) without --tablespace (-s)
|
|
||||||
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 -S
|
|
||||||
ERROR: cannot specify --moveidx (-S) without --tablespace (-s)
|
|
||||||
-- not broken with order
|
|
||||||
\! pg_repack --dbname=contrib_regression -o id --table=testts1 --tablespace pg_default --moveidx
|
|
||||||
INFO: repacking table "testts1"
|
|
||||||
--move all indexes of the table to a tablespace
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --tablespace=testts
|
|
||||||
INFO: repacking indexes of "testts1"
|
|
||||||
INFO: repacking index "public"."testts1_partial_idx"
|
|
||||||
INFO: repacking index "public"."testts1_pkey"
|
|
||||||
INFO: repacking index "public"."testts1_with_idx"
|
|
||||||
SELECT relname, spcname
|
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
|
||||||
WHERE relname ~ '^testts1'
|
|
||||||
ORDER BY relname;
|
|
||||||
relname | spcname
|
|
||||||
---------------------+---------
|
|
||||||
testts1_partial_idx | testts
|
|
||||||
testts1_pkey | testts
|
|
||||||
testts1_with_idx | testts
|
|
||||||
(3 rows)
|
|
||||||
|
|
||||||
--all indexes of tablespace remain in same tablespace
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes
|
|
||||||
INFO: repacking indexes of "testts1"
|
|
||||||
INFO: repacking index "public"."testts1_partial_idx"
|
|
||||||
INFO: repacking index "public"."testts1_pkey"
|
|
||||||
INFO: repacking index "public"."testts1_with_idx"
|
|
||||||
SELECT relname, spcname
|
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
|
||||||
WHERE relname ~ '^testts1'
|
|
||||||
ORDER BY relname;
|
|
||||||
relname | spcname
|
|
||||||
---------------------+---------
|
|
||||||
testts1_partial_idx | testts
|
|
||||||
testts1_pkey | testts
|
|
||||||
testts1_with_idx | testts
|
|
||||||
(3 rows)
|
|
||||||
|
|
||||||
--move all indexes of the table to pg_default
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --tablespace=pg_default
|
|
||||||
INFO: repacking indexes of "testts1"
|
|
||||||
INFO: repacking index "public"."testts1_partial_idx"
|
|
||||||
INFO: repacking index "public"."testts1_pkey"
|
|
||||||
INFO: repacking index "public"."testts1_with_idx"
|
|
||||||
SELECT relname, spcname
|
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
|
||||||
WHERE relname ~ '^testts1'
|
|
||||||
ORDER BY relname;
|
|
||||||
relname | spcname
|
|
||||||
---------+---------
|
|
||||||
(0 rows)
|
|
||||||
|
|
||||||
--move one index to a tablespace
|
|
||||||
\! pg_repack --dbname=contrib_regression --index=testts1_pkey --tablespace=testts
|
|
||||||
INFO: repacking index "public"."testts1_pkey"
|
|
||||||
SELECT relname, spcname
|
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
|
||||||
WHERE relname ~ '^testts1'
|
|
||||||
ORDER BY relname;
|
|
||||||
relname | spcname
|
|
||||||
--------------+---------
|
|
||||||
testts1_pkey | testts
|
|
||||||
(1 row)
|
|
||||||
|
|
||||||
--index tablespace stays as is
|
|
||||||
\! pg_repack --dbname=contrib_regression --index=testts1_pkey
|
|
||||||
INFO: repacking index "public"."testts1_pkey"
|
|
||||||
SELECT relname, spcname
|
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
|
||||||
WHERE relname ~ '^testts1'
|
|
||||||
ORDER BY relname;
|
|
||||||
relname | spcname
|
|
||||||
--------------+---------
|
|
||||||
testts1_pkey | testts
|
|
||||||
(1 row)
|
|
||||||
|
|
||||||
--move index to pg_default
|
|
||||||
\! pg_repack --dbname=contrib_regression --index=testts1_pkey --tablespace=pg_default
|
|
||||||
INFO: repacking index "public"."testts1_pkey"
|
|
||||||
SELECT relname, spcname
|
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
|
||||||
WHERE relname ~ '^testts1'
|
|
||||||
ORDER BY relname;
|
|
||||||
relname | spcname
|
|
||||||
---------+---------
|
|
||||||
(0 rows)
|
|
||||||
|
|
||||||
--using multiple --index option
|
|
||||||
\! pg_repack --dbname=contrib_regression --index=testts1_pkey --index=testts1_with_idx --tablespace=testts
|
|
||||||
INFO: repacking index "public"."testts1_pkey"
|
|
||||||
INFO: repacking index "public"."testts1_with_idx"
|
|
||||||
SELECT relname, spcname
|
|
||||||
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
|
|
||||||
WHERE relname ~ '^testts1'
|
|
||||||
ORDER BY relname;
|
|
||||||
relname | spcname
|
|
||||||
------------------+---------
|
|
||||||
testts1_pkey | testts
|
|
||||||
testts1_with_idx | testts
|
|
||||||
(2 rows)
|
|
||||||
|
|
||||||
--using --indexes-only and --index option together
|
|
||||||
\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --index=testts1_pkey
|
|
||||||
ERROR: cannot specify --index (-i) and --table (-t)
|
|
@ -1,5 +0,0 @@
|
|||||||
SET client_min_messages = warning;
|
|
||||||
\set ECHO none
|
|
||||||
\i ../lib/pg_repack.sql
|
|
||||||
\set ECHO all
|
|
||||||
RESET client_min_messages;
|
|
@ -1 +0,0 @@
|
|||||||
CREATE LANGUAGE plpgsql;
|
|
@ -66,6 +66,21 @@ CREATE TABLE tbl_idxopts (
|
|||||||
);
|
);
|
||||||
CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa');
|
CREATE INDEX idxopts_t ON tbl_idxopts (t DESC NULLS LAST) WHERE (t != 'aaa');
|
||||||
|
|
||||||
|
-- Use this table to play with attribute options too
|
||||||
|
ALTER TABLE tbl_idxopts ALTER i SET STATISTICS 1;
|
||||||
|
ALTER TABLE tbl_idxopts ALTER t SET (n_distinct = -0.5);
|
||||||
|
CREATE TABLE tbl_with_toast (
|
||||||
|
i integer PRIMARY KEY,
|
||||||
|
c text
|
||||||
|
);
|
||||||
|
ALTER TABLE tbl_with_toast SET (AUTOVACUUM_VACUUM_SCALE_FACTOR = 30, AUTOVACUUM_VACUUM_THRESHOLD = 300);
|
||||||
|
ALTER TABLE tbl_with_toast SET (TOAST.AUTOVACUUM_VACUUM_SCALE_FACTOR = 40, TOAST.AUTOVACUUM_VACUUM_THRESHOLD = 400);
|
||||||
|
CREATE TABLE tbl_with_mod_column_storage (
|
||||||
|
id integer PRIMARY KEY,
|
||||||
|
c text
|
||||||
|
);
|
||||||
|
ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- insert data
|
-- insert data
|
||||||
--
|
--
|
||||||
@ -101,6 +116,9 @@ ALTER TABLE tbl_with_dropped_toast DROP COLUMN t;
|
|||||||
INSERT INTO tbl_badindex VALUES(1, 10);
|
INSERT INTO tbl_badindex VALUES(1, 10);
|
||||||
INSERT INTO tbl_badindex VALUES(2, 10);
|
INSERT INTO tbl_badindex VALUES(2, 10);
|
||||||
|
|
||||||
|
-- insert data that is always stored into the toast table if column type is extended.
|
||||||
|
INSERT INTO tbl_with_mod_column_storage SELECT 1, array_to_string(ARRAY(SELECT chr(code) FROM generate_series(33,3000) code), '');
|
||||||
|
|
||||||
-- This will fail. Silence the message as it's different across PG versions.
|
-- This will fail. Silence the message as it's different across PG versions.
|
||||||
SET client_min_messages = fatal;
|
SET client_min_messages = fatal;
|
||||||
CREATE UNIQUE INDEX CONCURRENTLY idx_badindex_n ON tbl_badindex (n);
|
CREATE UNIQUE INDEX CONCURRENTLY idx_badindex_n ON tbl_badindex (n);
|
||||||
@ -136,23 +154,33 @@ SELECT * FROM tbl_with_dropped_toast;
|
|||||||
\d tbl_with_dropped_toast
|
\d tbl_with_dropped_toast
|
||||||
\d tbl_idxopts
|
\d tbl_idxopts
|
||||||
|
|
||||||
SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster;
|
SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster ORDER BY 1, 2;
|
||||||
SELECT * FROM tbl_only_ckey ORDER BY 1;
|
SELECT * FROM tbl_only_ckey ORDER BY 1;
|
||||||
SELECT * FROM tbl_only_pkey ORDER BY 1;
|
SELECT * FROM tbl_only_pkey ORDER BY 1;
|
||||||
SELECT * FROM tbl_gistkey ORDER BY 1;
|
SELECT * FROM tbl_gistkey ORDER BY 1;
|
||||||
|
|
||||||
SET enable_seqscan = on;
|
SET enable_seqscan = on;
|
||||||
SET enable_indexscan = off;
|
SET enable_indexscan = off;
|
||||||
SELECT * FROM tbl_with_dropped_column;
|
SELECT * FROM tbl_with_dropped_column ;
|
||||||
SELECT * FROM view_for_dropped_column;
|
SELECT * FROM view_for_dropped_column ORDER BY 1, 2;
|
||||||
SELECT * FROM tbl_with_dropped_toast;
|
SELECT * FROM tbl_with_dropped_toast;
|
||||||
SET enable_seqscan = off;
|
SET enable_seqscan = off;
|
||||||
SET enable_indexscan = on;
|
SET enable_indexscan = on;
|
||||||
SELECT * FROM tbl_with_dropped_column;
|
SELECT * FROM tbl_with_dropped_column ORDER BY 1, 2;
|
||||||
SELECT * FROM view_for_dropped_column;
|
SELECT * FROM view_for_dropped_column;
|
||||||
SELECT * FROM tbl_with_dropped_toast;
|
SELECT * FROM tbl_with_dropped_toast;
|
||||||
RESET enable_seqscan;
|
RESET enable_seqscan;
|
||||||
RESET enable_indexscan;
|
RESET enable_indexscan;
|
||||||
|
-- check if storage option for both table and TOAST table didn't go away.
|
||||||
|
SELECT CASE relkind
|
||||||
|
WHEN 'r' THEN relname
|
||||||
|
WHEN 't' THEN 'toast_table'
|
||||||
|
END as table,
|
||||||
|
reloptions
|
||||||
|
FROM pg_class
|
||||||
|
WHERE relname = 'tbl_with_toast' OR relname = 'pg_toast_' || 'tbl_with_toast'::regclass::oid
|
||||||
|
ORDER BY 1;
|
||||||
|
SELECT pg_relation_size(reltoastrelid) = 0 as check_toast_rel_size FROM pg_class WHERE relname = 'tbl_with_mod_column_storage';
|
||||||
|
|
||||||
--
|
--
|
||||||
-- check broken links or orphan toast relations
|
-- check broken links or orphan toast relations
|
||||||
@ -168,6 +196,13 @@ SELECT oid, relname
|
|||||||
AND reltoastrelid <> 0
|
AND reltoastrelid <> 0
|
||||||
AND reltoastrelid NOT IN (SELECT oid FROM pg_class WHERE relkind = 't');
|
AND reltoastrelid NOT IN (SELECT oid FROM pg_class WHERE relkind = 't');
|
||||||
|
|
||||||
|
-- check columns options
|
||||||
|
SELECT attname, attstattarget, attoptions
|
||||||
|
FROM pg_attribute
|
||||||
|
WHERE attrelid = 'tbl_idxopts'::regclass
|
||||||
|
AND attnum > 0
|
||||||
|
ORDER BY attnum;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- NOT NULL UNIQUE
|
-- NOT NULL UNIQUE
|
||||||
--
|
--
|
||||||
|
Loading…
x
Reference in New Issue
Block a user