Skip to content

Support for tablespaces #8314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 103 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
de87348
Port of TABLESPACES implementation from RedDatabase
romansimakov Apr 17, 2020
1c5d6fe
Merge remote-tracking branch 'origin/firebird_master' into port2fireb…
romansimakov Jan 10, 2021
2f9ac74
Now checks and erasing are performed in transaction and
romansimakov May 16, 2020
766fc1b
Avoid deleting an index tree if it does not exist
romansimakov May 28, 2020
1cf0b81
Wrong constant for the object.
romansimakov May 28, 2020
6598a01
Now to delete the tables while deleting a tablespace we use the same …
romansimakov Jun 10, 2020
390547a
Now we get tablespace before operations on index data and by the mome…
romansimakov Jun 17, 2020
5eeaddd
Added looking up tablespace in BTR_description after reading pagespac…
romansimakov Jun 20, 2020
bb73db9
Corrupted index after altering its tablespace
romansimakov Jul 17, 2020
30b58c4
Do not allow ALTER TABLESPACE for tables which are not commited. RDB$…
ilya071294 May 13, 2021
9bb1f42
Remove wrong line which was added accidentally during merge
ilya071294 May 13, 2021
f8c52a8
Fix race condition when several attachments are simultaneously findin…
ilya071294 May 13, 2021
09b9ae7
Remove assertion which is wrong because pageSpace is NULL during tabl…
ilya071294 May 13, 2021
83630ed
Fix closing and deletion of tablespace file after DROP TABLESPACE <NA…
ilya071294 May 13, 2021
e2929aa
Do not create tablespace file immediately at CREATE TABLESPACE to mak…
ilya071294 May 13, 2021
f44a17d
Post dfw_drop_tablespace before trigger execution like in other DDL n…
ilya071294 May 13, 2021
89b2dc2
Do not allow to ALTER TABLESPACE for a table if the tablespace was dr…
ilya071294 May 13, 2021
d2cdd8e
Fix crash by checking existence of a relation at dfw_clear_datapages.…
ilya071294 May 13, 2021
70469e6
Print ID of a missing tablespace in the error message
ilya071294 May 13, 2021
9f1aa54
Get the SR lock for a tablespace when putting it into tablespaces cache
ilya071294 May 13, 2021
b709ae1
Do not try to find a tablespace during ALTER TABLE DROP TABLESPACE to…
ilya071294 May 13, 2021
ca7a668
Avoid assertion failure in ~thread_db() when opening of a tablespace …
ilya071294 May 13, 2021
72a92fb
Flush DB pages before closing a tablespace file. It prevents server c…
ilya071294 May 13, 2021
df16a6e
Do not allow to ALTER TABLESPACE for an index if the tablespace was d…
ilya071294 May 13, 2021
c8c9876
Do not move index pages when the index is deleted in the same transac…
ilya071294 May 13, 2021
936f2dd
Fix build
ilya071294 May 13, 2021
4e66b10
Merge branch 'firebird_master' into port2firebird_tablespaces
ilya071294 Apr 4, 2022
7426dac
Add ability to ALTER TABLESPACE for tables which are not committed
ilya071294 Apr 8, 2022
75d81b3
Fix DROP TABLE for tables which are not committed
ilya071294 Apr 8, 2022
b8ef3d5
Add some useful assertions for SR lock of tablespace
ilya071294 Apr 8, 2022
2bc0e21
Remove redundant code which was accidentally added during merge of ta…
ilya071294 Apr 8, 2022
a2a0867
Put a relation into cache only if opening of a tablespace file contai…
ilya071294 Apr 8, 2022
ebea006
Fix error messages and gbak help
ilya071294 Apr 8, 2022
31cb30e
Open a tablespace file during index deletion to fix crash when DROP I…
ilya071294 Apr 8, 2022
37b8c07
Don't call MET_tablespace function here because it's already called i…
ilya071294 Apr 8, 2022
7a56031
Eliminate situation when an index implicitly moves from one tablespac…
ilya071294 Apr 8, 2022
e4d2d72
Fix an issue when pages of indexes for GTT were allocated in DB_PAGE_…
ilya071294 Apr 8, 2022
c41c2bd
Add TABLESPACE DEFAULT clause to CREATE INDEX
ilya071294 Apr 8, 2022
344a610
Restore const qualifiers. Use RWLock on page spaces only if SuperServ…
ilya071294 Apr 8, 2022
035b504
1. If TABLESPACE clause is omitted in CREATE INDEX, an index will use…
ilya071294 Apr 8, 2022
d1ae05e
Use checkObjectExist() function in appropriate places
ilya071294 Apr 8, 2022
9741cff
Do not recreate an index if ALTER INDEX specifies a tablespace which …
ilya071294 Apr 8, 2022
095034f
Add an ability to specify a tablespace for PK, FK, UNIQUE constraints…
ilya071294 Apr 8, 2022
ac0990c
Add tablespace-related header files to VS projects
ilya071294 Apr 8, 2022
80cb22e
Temporarily disable tablespace-related clauses which are not fully im…
ilya071294 Apr 8, 2022
16f6593
Do not allow to use SET TABLESPACE clause in ALTER TABLE more than once
ilya071294 Apr 8, 2022
039e3ef
Fix typos in the error message and comments
ilya071294 Apr 8, 2022
d9e66fc
Change the data type of RDB$OFFLINE and RDB$READ_ONLY to BOOLEAN
ilya071294 Apr 8, 2022
cf021e6
Always store an absolute path to a tablespace file in RDB$TABLESPACES
ilya071294 Apr 8, 2022
a2066fa
Do not allow to restore a database if paths for some tablespaces are …
ilya071294 Apr 8, 2022
cbe164e
Restrict access to tablespace files by DatabaseAccess entry of firebi…
ilya071294 Apr 8, 2022
a480ce2
Add -TABLESPACE_ORIG(INAL_PATHS) option to gbak which allows to resto…
ilya071294 Apr 8, 2022
1159813
Add -TS <tablespace> <path> option to gbak which allows to set a path…
ilya071294 Apr 8, 2022
66c7fde
1. Read tablespace names from a mapping file as case sensitive.
ilya071294 Apr 8, 2022
112012b
Rename gbak options -TABLESPACE_* to -TS_*
ilya071294 Apr 8, 2022
eb097ad
Correct the argument of the error message
ilya071294 Apr 8, 2022
a9430d4
Fix the phase 0 of create_tablespace DFW
ilya071294 Apr 8, 2022
282a198
Do not allow to set a tablespace for GTT's indexes
ilya071294 Apr 8, 2022
49c6fbf
Release the exclusive lock on a database after moving a relation or a…
ilya071294 Apr 8, 2022
503ab38
Add missing tablespaces-related messages
ilya071294 Apr 12, 2022
9ff293d
Fix build
ilya071294 Apr 12, 2022
bb40f20
Fix assertion at TipCache::generateStatementId()
ilya071294 Apr 12, 2022
9e07d5c
Fix usage of tablespaces-related messages
ilya071294 Apr 15, 2022
00cd260
Increase ODS version to 14.0 and backup version to 12
ilya071294 Apr 15, 2022
1557ca5
Undo changes which are not related to tablespaces
ilya071294 May 4, 2022
9f3fa6b
Remove unused BTR_delete_index argument
ilya071294 May 5, 2022
ca374ee
Remove unused function
ilya071294 May 5, 2022
d898f74
Correct copyright and comments
ilya071294 May 5, 2022
c1d6e88
Correct code formatting
ilya071294 May 5, 2022
5634fb6
1. Remove unused startSequence argument from DPM_scan_pages().
ilya071294 May 6, 2022
4dce809
Fix warning
ilya071294 May 6, 2022
ec37910
Merge branch 'firebird_master' into port2firebird_tablespaces
Jul 11, 2024
c3a8314
Fixed errors after merge with firebird_master
Jul 11, 2024
5ff5d24
Fix a bug when it was possible to create several tablespaces with the…
ilya071294 May 13, 2022
06d819a
Use 4-byte unsigned integer for page space id
ilya071294 May 16, 2022
63e2418
Temporarily reduce the maximum amount of tablespaces
ilya071294 May 18, 2022
3d51bcb
Create ObjectsArray in the default memory pool instead of the dbb per…
ilya071294 May 20, 2022
3a7b980
Do not store tablespaces privileges in RDB$USER_PRIVILEGES because th…
ilya071294 Jun 21, 2022
c31777e
Add apply_tablespaces_ddl parameter to replication.conf
ilya071294 Jun 8, 2022
d8be9fe
Always enable replication if a plugin name is specified in replicatio…
ilya071294 Jul 8, 2022
2f1a46b
Add a missing argument to gfix message about inconsistent flags
ilya071294 Jan 16, 2023
9753088
Fix an ambiguity in the parser which causes the server to crash due t…
ilya071294 Oct 9, 2023
cdacf7a
Flush only pages from a page space of a tablespace which is being alt…
ilya071294 Mar 30, 2022
9adb486
Delete indexes after tables during DROP TABLESPACE INCLUDING CONTENTS…
ilya071294 Sep 5, 2022
8a3436a
Do not execute DDL triggers for a table when it's deleted during DROP…
ilya071294 Sep 5, 2022
bbebeaa
Disable INCLUDING CONTENTS clause in DROP TABLESPACE because it still…
ilya071294 Sep 9, 2022
b3ffd1c
fix after tablespace porting
Jul 16, 2024
55d3f60
Added ability to comment on tablespaces
Aug 5, 2024
39553b7
Added "IF EXISTS" for drop clause for tablespace
Aug 5, 2024
785a411
Added CREATE IF NOT EXISTS for tablespaces
Aug 5, 2024
55dfad1
Merge branch 'firebird_master' into port2firebird_tablespaces2
Oct 28, 2024
5747e47
Fix the show tablespace TS command error
Oct 28, 2024
794912a
Fix inability to create TS after BEGIN BACKUP
Sep 19, 2024
47d48a2
Fix create/alter TS clauses after merge
Oct 28, 2024
423a62e
Merge branch 'firebird_master' into port2firebird_tablespaces2
Nov 11, 2024
cabcf28
fix restore TS error: validation error for column RDB$TABLESPACE_ID v…
Nov 7, 2024
ac94102
Increase ODS version for FB 6.0
Nov 11, 2024
55c7d81
Add small fixes after the TS porting branch update
Nov 11, 2024
362ee8d
Try to fix windows build for tablespaces
Nov 12, 2024
b3ffc01
Merge branch 'master' into port2firebird_tablespaces2
Nov 12, 2024
9c87830
Try to fix macos build for tablespaces
Nov 12, 2024
c94f003
Add readme.tablespaces
Mar 20, 2025
c84ca58
Add the ability to move the contents of a tablespace to PRIMARY durin…
Mar 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion builds/install/misc/replication.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ database
# with an ordinal sequential number. If not specified, database filename
# (without path) is used as a prefix.
#
# journal_file_prefix =
# journal_file_prefix =

# Maximum allowed size for a single replication segment.
#
Expand Down Expand Up @@ -162,6 +162,11 @@ database
# then reconnects back and tries to re-apply the latest segments from the point of failure.
#
# apply_error_timeout = 60

# If disabled, tablespaces-related DDL statements and clauses in
# CREATE/ALTER TABLE/INDEX will not be applied to the replica.
#
# apply_tablespaces_ddl = true
}

#
Expand Down
3 changes: 3 additions & 0 deletions builds/posix/make.shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ $(OBJ)/dsql/DdlNodes.cpp: $(SRC_ROOT)/dsql/DdlNodes.epp
$(OBJ)/dsql/PackageNodes.cpp: $(SRC_ROOT)/dsql/PackageNodes.epp
$(GPRE_CURRENT) $(JRD_GPRE_FLAGS) $< $@

$(OBJ)/dsql/TablespaceNodes.cpp: $(SRC_ROOT)/dsql/TablespaceNodes.epp
$(GPRE_CURRENT) $(JRD_GPRE_FLAGS) $< $@

# Adding resources as prerequisite for some files

$(FilesToAddVersionInfo): $(GEN_ROOT)/jrd/version.res
Expand Down
2 changes: 1 addition & 1 deletion builds/win32/msvc15/engine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
5 changes: 5 additions & 0 deletions builds/win32/msvc15/engine_static.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<ClCompile Include="..\..\..\gen\dsql\DdlNodes.cpp" />
<ClCompile Include="..\..\..\gen\dsql\metd.cpp" />
<ClCompile Include="..\..\..\gen\dsql\PackageNodes.cpp" />
<ClCompile Include="..\..\..\gen\dsql\TablespaceNodes.cpp" />
<ClCompile Include="..\..\..\gen\jrd\dfw.cpp" />
<ClCompile Include="..\..\..\gen\jrd\dpm.cpp" />
<ClCompile Include="..\..\..\gen\jrd\dyn_util.cpp" />
Expand Down Expand Up @@ -166,6 +167,7 @@
<ClCompile Include="..\..\..\src\jrd\sys-packages\SqlPackage.cpp" />
<ClCompile Include="..\..\..\src\jrd\SysFunction.cpp" />
<ClCompile Include="..\..\..\src\jrd\SystemPackages.cpp" />
<ClCompile Include="..\..\..\src\jrd\Tablespace.cpp" />
<ClCompile Include="..\..\..\src\jrd\TempSpace.cpp" />
<ClCompile Include="..\..\..\src\jrd\TimeZone.cpp" />
<ClCompile Include="..\..\..\src\jrd\tpc.cpp" />
Expand Down Expand Up @@ -216,6 +218,7 @@
<ClInclude Include="..\..\..\src\dsql\sqlda_pub.h" />
<ClInclude Include="..\..\..\src\dsql\StmtNodes.h" />
<ClInclude Include="..\..\..\src\dsql\sym.h" />
<ClInclude Include="..\..\..\src\dsql\TablespaceNodes.h" />
<ClInclude Include="..\..\..\src\dsql\utld_proto.h" />
<ClInclude Include="..\..\..\src\dsql\Visitors.h" />
<ClInclude Include="..\..\..\src\dsql\WinNodes.h" />
Expand Down Expand Up @@ -352,6 +355,7 @@
<ClInclude Include="..\..\..\src\jrd\SysFunction.h" />
<ClInclude Include="..\..\..\src\jrd\SystemPackages.h" />
<ClInclude Include="..\..\..\src\jrd\SystemTriggers.h" />
<ClInclude Include="..\..\..\src\jrd\Tablespace.h" />
<ClInclude Include="..\..\..\src\jrd\TempSpace.h" />
<ClInclude Include="..\..\..\src\jrd\TimeZone.h" />
<ClInclude Include="..\..\..\src\jrd\tpc_proto.h" />
Expand Down Expand Up @@ -380,6 +384,7 @@
<None Include="..\..\..\src\dsql\DdlNodes.epp" />
<None Include="..\..\..\src\dsql\metd.epp" />
<None Include="..\..\..\src\dsql\PackageNodes.epp" />
<None Include="..\..\..\src\dsql\TablespaceNodes.epp" />
<None Include="..\..\..\src\dsql\parse.y">
<FileType>Document</FileType>
</None>
Expand Down
15 changes: 15 additions & 0 deletions builds/win32/msvc15/engine_static.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,9 @@
<ClCompile Include="..\..\..\gen\dsql\PackageNodes.cpp">
<Filter>DSQL\preprocesed</Filter>
</ClCompile>
<ClCompile Include="..\..\..\gen\dsql\TablespaceNodes.cpp">
<Filter>DSQL\preprocesed</Filter>
</ClCompile>
<ClCompile Include="..\..\..\gen\utilities\gstat\dba.cpp">
<Filter>Services</Filter>
</ClCompile>
Expand All @@ -477,6 +480,9 @@
<ClCompile Include="..\..\..\src\jrd\Routine.cpp">
<Filter>JRD files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\jrd\Tablespace.cpp">
<Filter>JRD files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\jrd\Mapping.cpp">
<Filter>JRD files</Filter>
</ClCompile>
Expand Down Expand Up @@ -1100,6 +1106,12 @@
<ClInclude Include="..\..\..\src\jrd\QualifiedName.h">
<Filter>Header files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\dsql\TablespaceNodes.h">
<Filter>Header files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\jrd\Tablespace.h">
<Filter>Header files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\jrd\InitCDSLib.h">
<Filter>Header files</Filter>
</ClInclude>
Expand All @@ -1118,6 +1130,9 @@
<None Include="..\..\..\src\dsql\PackageNodes.epp">
<Filter>DSQL\GPRE files</Filter>
</None>
<None Include="..\..\..\src\dsql\TablespaceNodes.epp">
<Filter>DSQL\GPRE files</Filter>
</None>
<None Include="..\..\..\src\jrd\dfw.epp">
<Filter>JRD files\GPRE files</Filter>
</None>
Expand Down
4 changes: 2 additions & 2 deletions builds/win32/preprocess.bat
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ goto :EOF

@set GPRE=%FB_BIN_DIR%\gpre_boot
@for %%i in (alice_meta) do @call :PREPROCESS alice %%i
@for %%i in (metd, DdlNodes, PackageNodes) do @call :PREPROCESS dsql %%i -gds_cxx
@for %%i in (metd, DdlNodes, PackageNodes, TablespaceNodes) do @call :PREPROCESS dsql %%i -gds_cxx
@for %%i in (gpre_meta) do @call :PREPROCESS gpre/std %%i
@for %%i in (dfw, dpm, dyn_util, fun, grant, ini, met, scl, Function, SystemTriggers) do @call :PREPROCESS jrd %%i -gds_cxx
@for %%i in (stats) do @call :PREPROCESS utilities %%i
Expand All @@ -76,7 +76,7 @@ goto :EOF
@for %%i in (LegacyManagement) do @call :PREPROCESS auth/SecurityDatabase %%i
@for %%i in (backup, restore, OdsDetection) do @call :PREPROCESS burp %%i -ocxx -m
@for %%i in (metd) do @call :PREPROCESS dsql %%i -gds_cxx
@for %%i in (DdlNodes, PackageNodes) do @call :PREPROCESS dsql %%i -gds_cxx
@for %%i in (DdlNodes, PackageNodes, TablespaceNodes) do @call :PREPROCESS dsql %%i -gds_cxx
@for %%i in (gpre_meta) do @call :PREPROCESS gpre/std %%i
@for %%i in (dfw, dpm, dyn_util, fun, grant, ini, met, scl, Function, SystemTriggers) do @call :PREPROCESS jrd %%i -gds_cxx
@for %%i in (extract, isql, show) do @call :PREPROCESS isql %%i -ocxx
Expand Down
189 changes: 189 additions & 0 deletions doc/README.tablespaces
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
-----------------
TABLESPACES
-----------------

Goals:
Tablespaces allow you to organize the logic of placing database object files in the file system. It allows:
1) Extend the current limits on database size
2) Keep non active parts of a database on slow disks (having big volume)
3) Split indices from the database

-----------------
SYNTAX
-----------------

1. TABLESPACE
CREATE TABLESPACE [IF NOT EXISTS] <TS NAME> FILE '/path/to/file'
ALTER TABLESPACE <TS NAME> SET FILE [TO] '/path/to/file'
You can specify either an absolute path or a relative path (relative to the database file)

DROP TABLESPACE [IF EXISTS] <TS NAME>
The development of the INCLUDING CONTENTS option has been postponed.

For an existing tablespace, it is possible to add a comment using the COMMENT ON statement.
COMMENT ON TABLESPACE <TS NAME> IS {'text' | NULL}

2. TABLE
"PRIMARY" keyword
The PRIMARY keyword can be used as a tablespace name if you want to reference the main database file.

CREATE TABLE ...
[[IN] TABLESPACE {<TS NAME> | PRIMARY}]

It is also possible to specify a tablespace when creating a column or table constraint (unique, primary key, references):

<column/table constraint> ::= ... UNIQUE ... [[IN] TABLESPACE {<TS NAME> | PRIMARY}] | PRIMARY ... [[IN] TABLESPACE {<TS NAME> | PRIMARY}] | REFERENCES ... [[IN] TABLESPACE {<TS NAME> | PRIMARY}] ...

ALTER TABLE <TABLE NAME> SET TABLESPACE [TO] {<TS NAME> | PRIMARY}

The table data will be moved to the specified tablespace or to the main database.

3. INDEX
CREATE INDEX ...
[[IN] TABLESPACE {<TS NAME> | PRIMARY}]

By default, table indexes are created in the same tablespace as the table itself.

ALTER INDEX ...
[SET TABLESPACE [TO] {<TS NAME> | PRIMARY}]

The index data will be moved to the specified tablespace or to the main database.

-----------------
SECURITY
-----------------

Only administrators and users with the “CREATE TABLESPACE” privilege can create tablespaces (CREATE TABLESPACE).
Only administrators and users with the “ALTER ANY TABLESPACE” privilege can change tablespaces file paths (ALTER TABLESPACE <name> SET FILE [TO] <file_name>).
Only administrators, domain owners, or users with the ALTER ANY TABLESPACE privilege can comment (COMMENT ON) tablespaces.
Only administrators and users with the “DROP ANY TABLESPACE” privilege can delete tablespaces (DROP TABLESPACE).

-----------------
ODS CHANGES
-----------------

A new table RDB$TABLESPACES:
RDB$TABLESPACE_ID - INTEGER # internally it will be pagespaceid.
RDB$TABLESPACE_NAME - CHAR (63) # name of a tablespace
RDB$SECURITY_CLASS - CHAR (63) # security class for tablespace
RDB$SYSTEM_FLAG - SMALLINT # reserved for future
RDB$DESCRIPTION - BLOB TEXT # description of a tablespace
RDB$OWNER_NAME - CHAR (63) # owner of a tablespace
RDB$FILE_NAME - VARCHAR (255) # file where a tablespace data are located
RDB$OFFLINE - BOOLEAN # reserved for future
RDB$READ_ONLY - BOOLEAN # reserved for future

New field in RDB$INDICES:
RDB$TABLESPACE_NAME - CHAR (63)

New field in RDB$RELATION_FIELDS:
RDB$TABLESPACE_NAME - CHAR (63)

New fields in RDB$RELATIONS:
RDB$TABLESPACE_NAME - CHAR (63)
RDB$POINTER_PAGE - INTEGER # a number of the first pointer page of a relation
RDB$ROOT_PAGE - INTEGER # a number of the root page of a relation

These fields are necessary for reliable implementation of moving data pages to another tablespace.
It's a dfw operation with EX database lock. So there are no concurrent changes.
1) copy all data pages
2) switch RDB$POINTER_PAGE and RDB$ROOT_PAGE transactionally
3) Rebuild RDB$PAGES
4) clear old data pages (as post-dfw operation)
It can be interrupted but not resumed.

-----------------
UTILITIES
-----------------

1. Logical backup
gbak -b works as usual for now. It gets data from a database transparently working with tablespaces.

2. Logical restore
gbak -c

-ts_map[ping] <path to file>
option is required for correct database restore if its backup contains tables or indexes saved in tablespaces.
To do this, specify the path to file, which consists of lines with two values: the first column is the name of the tablespace,
the second column is the new location of the tablespace. You can specify either an absolute path or a relative path.
TS1 /path/to/tablespace1.dat
TS2 /path/to/tablespace2.dat

-ts <tablespace> <path>
allows you to specify the path for the tablespace. You can specify either an absolute path or a relative path.
The option can be used as many times as required. It can also be used together with -ts_map.

If you specify “PRIMARY” instead of the path for the new tablespace, the contents of the tablespace will be moved to the PRIMARY tablespace.
The tablespace will not be created.

-ts_orig[inal_paths]
To restore tablespaces to the original paths they were on when the backup was created.
It is still possible to override paths for some tablespaces using the -ts and -ts_map options.
This is an explicit option, not a default action.
The option does not overwrite existing files.

If you do not specify the above options, when restoring a database that has tablespaces,
an error about the inability to determine the path to restore tablespaces will occur.

3. Show
SHOW {TABLESPACES | TABLESPACE <TS NAME>}
Displays a list of all tablespaces names in alphabetical order or information about the specified tablespace.

4. Replication
There is an apply_tablespaces_ddl parameter for replication.
If this parameter is disabled, tablespaces-related DDL statements and CREATE/ALTER TABLE/INDEX clauses will not be applied to the replica.
This is used if the replica has its own set of tablespaces or none at all.

-----------------
DETAILS
-----------------

pag_header in every tablespace is reserved and may be replaced by a
new page type.
pag_scns and pag_pip are located in every tablespace.
pag_root is located in the tablespace where a table is located.

An algorithm for moving data to another tablespace:
First, you have to move all the pages to another tablespace:
The main steps are:
- allocate necessary number of pointer pages by extents.
- allocate the rest of pointer pages by pages.
- walking through PPs allocate DPs by pages or extents.
- fix every PP by correcting DP numbers and ppg_next pointer and build a map
- walking through the map and copy every DP to the new one by fixing
b_page and f_page numbers.
At the end of work replace records in RDB$PAGES.

Then you need to update first pointer page and root page in RDB$RELATIONS transactionally.

RDB$POINTER_PAGE and RDB$ROOT_PAGE are updated in a transaction because:
Moving table pages to another tablespace occurs in DFW. In case of failure, we can get the old values of RDB$POINTER_PAGE and RDB$ROOT_PAGE fields.

Then we delete all from RDB$PAGES about the relation to have an ability to understand that we need to restore pages
if transaction won't be able to finish successfully.

Then post commit work will clean up old pages. It must be done exactly after commit.
If crash is happend the metadata will point to the old page space and new ones will be garbage. Right after commit old pages will be garbage.


-----------------
CONSTRAINTS
-----------------

It's possible to create up to 253 tablespaces.
Operators to move an index or table to a tablespace require an exclusive database lock.

-----------------
PLANS
-----------------

1. Add the main database file to the RDB$TABLESPACES table. Designate it as PRIMARY.
The RDB$TABLESPACE_NAME field contained in the system tables of tables, indexes will have the value “PRIMARY” instead of NULL.
2. TEMPORARY predefined tablespaces.
3. Grouping page counters by tablespace (For output in trace and monitoring).
4. New header page for tablespaces
5. NBACKUP support for tablespaces
6. Moving blobs to separate tablespaces (The RDB$TABLESPACE_NAME column in RDB$RELATION_FIELDS is reserved for this purpose).
7. Possibility to introduce UNDO tablespace in future versions
8. The ability to set default tablespaces for tables, indexes and BLOBs at the database or schema level.

2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ set(epp_boot_gds_files
dsql/metd.epp
dsql/DdlNodes.epp
dsql/PackageNodes.epp
dsql/TablespaceNodes.epp
jrd/dfw.epp
jrd/dpm.epp
jrd/dyn_util.epp
Expand Down Expand Up @@ -469,6 +470,7 @@ set(engine_generated_src
dsql/DdlNodes.epp
dsql/metd.epp
dsql/PackageNodes.epp
dsql/TablespaceNodes.epp
jrd/dfw.epp
jrd/dpm.epp
jrd/dyn_util.epp
Expand Down
1 change: 1 addition & 0 deletions src/burp/OdsDetection.epp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace
{"RDB$ROLES", 0, DB_VERSION_DDL9}, // IB5
{"RDB$PACKAGES", 0, DB_VERSION_DDL12}, // FB3
{"RDB$PUBLICATIONS", 0, DB_VERSION_DDL13}, // FB4
{"RDB$TABLESPACES", 0, DB_VERSION_DDL14}, // FB6
{0, 0, 0}
};

Expand Down
1 change: 1 addition & 0 deletions src/burp/OdsDetection.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const int DB_VERSION_DDL11_2 = 112; // ods11.2 db, FB2.5
const int DB_VERSION_DDL12 = 120; // ods12.0 db, FB3.0
const int DB_VERSION_DDL13 = 130; // ods13.0 db, FB4.0
const int DB_VERSION_DDL13_1 = 131; // ods13.1 db, FB5.0
const int DB_VERSION_DDL14 = 140; // ods14.0 db, FB6.0

const int DB_VERSION_OLDEST_SUPPORTED = DB_VERSION_DDL8; // IB4.0 is ods8

Expand Down
Loading