==============================================================================
PROPOSAL
==============================================================================
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
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
CREATE TABLE ...
[[IN] TABLESPACE {<TS NAME> | PRIMARY}]
It is also possible to specify a tablespace when creating a column or table constraint:
<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.
It is also possible to specify a tablespace when adding column or table constraints.
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.
ODS CHANGES
=============
A new table RDB$TABLESPACES:
RDB$TABLESPACE_ID - INTEGER # internally it will be pagespaceid.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
========
Logical backup
--------------------
gbak -b works as usual for now. It gets data from a database
transparently working with tablespaces.
Logical restore
--------------------
gbak -c
-ts_map[ping] <path to file>
option is required for
correct database recovery 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.
-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.
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.
NBACKUP
--------------------
ALTER DATABASE {BEGIN | END}
BACKUP will put not only the main database file, but also all
tablespaces into safe copy mode. A delta file will be created for each
tablespace.
SHOW
--------------------
SHOW {TABLESPACES | TABLESPACE <TS NAME>}
Displays a list of all ts names in alphabetical order or information about the specified ts
REPLIACTION
==========
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.
If the parameter is enabled, the following options are available:
1) Specify absolute path when creating TS. Then the replica machine should follow the directory hierarchy.
2) Specify relative path when creating TS.
3)
The first two options can be problematic if the master and replica are
on the same computer. Then there is the following solution:
Store directory aliases and their corresponding real paths in the configuration file for the master and replica.
For example:
db master
{
test_dir = /path/for/master
}
db replica
{
test_dir = /path/for/replica
}
Then the CREATE TABLESPACE
TS1 FILE 'test_dir/file_name' operation will cause the master to create
a tablespace using the path /path/for/master and the replica to use
/path/for/replica.
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.
CONSTRAINTS / PLANS
==========
It's possible to create up to 253 tablespaces.
Operators to move an index or table to a tablespace require an exclusive database lock.
We have plans to create functionality to move blobs to separate tablespaces.
On 09/09/2024 10:15, Alexander Zhdanov wrote:
>
> New field in RDB$RELATION_FIELDS:
>
> RDB$TABLESPACE_NAME - CHAR (63)
>
Why a field has a tablespace? Is it for blobs? (AFAIU this functionality
is not specified and them should not be "reserved" IMO).
> Logical restore
> --------------------
> gbak -c
>
> -ts_map[ping] <path to file>
> option is required for correct database recovery 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.
>
Can PRIMARY be moved to external tablespace when restoring?
Is PRIMARY listed in RDB$TABLESPACES?
Adriano
Why not create a tablespace (whatever that is) specifically for
blobs?
--
You received this message because you are subscribed to the Google Groups "firebird-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebird-devel/4ed0ab5f-16b9-4947-856a-c76e3dc8d068n%40googlegroups.com.
+1
Regards,
Karol Bieniaszewski
--
You received this message because you are subscribed to the Google Groups "firebird-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebird-devel/882d8689-5404-4ade-ae75-1d20975e5d3c%40lawinegevaar.nl.
>> NBACKUP
>> --------------------
>> ALTER DATABASE {BEGIN | END} BACKUP will put not only the main database file, but also all tablespaces into safe copy mode. A delta file will be created for each tablespace.We have the following syntax to specify the default delta file name and path for it.ALTER DATABASEADD DIFFERENCE FILE 'diff_file'| DROP DIFFERENCE FILESo it turns out that we have to provide the same capability for each tablespace?
09.09.2024 16:15, Alexander Zhdanov:
> Hello! This is the second part of the discussion on tablespaces. Getting ready to port tablespaces to FB.
> Link to the first part: https://sourceforge.net/p/firebird/mailman/firebird-devel/thread/a87823d8-971f-fb4d-
> a80d-2637549d8426%40ibphoenix.com/#msg37365238
> 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
And relative path will be relative to... what ?
Will tablespace get additional properties except of file name ?
Will be there predefined tablespaces ? I see PRIMARY, what about TEMPORARY ?
> CREATE TABLE ...
> [[IN] TABLESPACE {<TS NAME> | PRIMARY}]
Would be good to explain what is a PRIMARY before referencing it.
> It is also possible to specify a tablespace when creating a column or table constraint:
Even NOT NULL and CHECK constraints ?
> <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.
> It is also possible to specify a tablespace when adding column or table constraints.
You speak about ALTER TABLE ADD CONSTRAINT statement here, correct ?
> 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
What actions with tablespaces will be secured ? What SQL syntax ?
> RDB$SYSTEM_FLAG - SMALLINT # reserved
> RDB$DESCRIPTION - BLOB TEXT # description of a tablespace
> RDB$OWNER_NAME - CHAR (63) # owner of a tablespace
What is a role of tablespace owner ?
> New field in RDB$INDICES:
>
> RDB$TABLESPACE_NAME - CHAR (63)
Is it nullable or not ?
> 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
In most places in code we use IRT or 'index root page' (Ods::index_root_page),
lets' not break its name. It is also important to not confuse IRT with root page
of index B-Tree.
RDB$ROOT_PAGE points to the some page in relation's tablespace. The IRT contains
root pages of every index (index_root_page::irt_repeat::irt_root). How to get the
each index pagespace ID looking at IRT contents ? Or engine should first read
RDB$INDICES ?
> 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
Could you explain a bit more this point ?
Also, should it be also done "transactionally" ?
>
> Logical restore
> --------------------
> gbak -c
>
> -ts_map[ping] <path to file>
> option is required for correct database recovery 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.
What happens if both options contains same tablespace or file ?
> -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.
Will it overwrite existing file(s) ?
> 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.
Is there a way to merge (redirect) few tablespaces from backup file into single
tablespace ? For example, put all into single database file ?
> NBACKUP
> --------------------
> ALTER DATABASE {BEGIN | END} BACKUP will put not only the main database file, but also all tablespaces into safe copy mode. A delta
> file will be created for each tablespace.
Where all that delta files will reside ?
> SHOW
> --------------------
> SHOW {TABLESPACES | TABLESPACE <TS NAME>}
> Displays a list of all ts names in alphabetical order or information about the specified ts
This one about isql command, correct ?
> REPLIACTION
>
> ==========
>
> 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.
Looks like replication.conf's parameter for replica side, correct ?
Parameter is per-replica and have a boolean type, correct ?
> If the parameter is enabled, the following options are available:
> 1) Specify absolute path when creating TS. Then the replica machine should follow the directory hierarchy.
> 2) Specify relative path when creating TS.
Again: relative to what ?
> 3) The first two options can be problematic if the master and replica are on the same computer. Then there is the following solution:
> Store directory aliases and their corresponding real paths in the configuration file for the master and replica.
> For example:
> db master {
> test_dir = /path/for/master
> }
> db replica {
> test_dir = /path/for/replica
> }
Not sure I got the configuration syntax above. It definitely can not
work in this way, AFAIU. Perhaps you going to use something like:
database = path
{
...
ts_directory_aliases =
{
test_dir1 = /path1
test_dir2 = /path2
...
}
}
Or you have another idea ?
>
> DETAILS
>
> ==========
>
> pag_header in every tablespace is reserved and may be replaced by a
> new page type.
Don't understand, sorry. Is it reserved or replaced (by what) ?
> pag_scns and pag_pip are located in every tablespace.
> pag_root is located in the tablespace where a table is located.
What about RDB$PAGES ? I see no changes for it (no tablespace field) thus
I suppose every tablespace will have a local instance of RDB$PAGES ?
> CONSTRAINTS / PLANS
>
> ==========
>
> It's possible to create up to 253 tablespaces.
> Operators to move an index or table to a tablespace require an exclusive database lock.
> We have plans to create functionality to move blobs to separate tablespaces.
Thank you for the proposal and for the job done. But, please, take into account
that not everyone is close to the (not published yet) code and knows every detail.
Description above is very draft (I understand) and raises a lot of questions that
you may consider well known or explicitly known, etc ;)
Mark
--
Mark Rotteveel
Hello! This is the second part of the discussion on tablespaces. Getting ready to port tablespaces to FB.
Link to the first part: https://sourceforge.net/p/firebird/mailman/firebird-devel/thread/a87823d8-971f-fb4d-a80d-2637549d8426%40ibphoenix.com/#msg37365238
==============================================================================
PROPOSAL==============================================================================
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
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
CREATE TABLE ...
[[IN] TABLESPACE {<TS NAME> | PRIMARY}]
It is also possible to specify a tablespace when creating a column or table constraint:
<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.
It is also possible to specify a tablespace when adding column or table constraints.
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.
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
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
========
Logical backup
--------------------
gbak -b works as usual for now. It gets data from a database
transparently working with tablespaces.
Logical restore
--------------------
gbak -c
-ts_map[ping] <path to file>
option is required for correct database recovery 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.
-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.
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.
NBACKUP
--------------------
ALTER DATABASE {BEGIN | END} BACKUP will put not only the main database file, but also all tablespaces into safe copy mode. A delta file will be created for each tablespace.
SHOW
--------------------
SHOW {TABLESPACES | TABLESPACE <TS NAME>}
Displays a list of all ts names in alphabetical order or information about the specified ts
REPLIACTION
==========
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.
If the parameter is enabled, the following options are available:
1) Specify absolute path when creating TS. Then the replica machine should follow the directory hierarchy.
2) Specify relative path when creating TS.
3) The first two options can be problematic if the master and replica are on the same computer. Then there is the following solution:
Store directory aliases and their corresponding real paths in the configuration file for the master and replica.
For example:
db master {
test_dir = /path/for/master
}
db replica {
test_dir = /path/for/replica
}
Then the CREATE TABLESPACE TS1 FILE 'test_dir/file_name' operation will cause the master to create a tablespace using the path /path/for/master and the replica to use /path/for/replica.
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.
CONSTRAINTS / PLANS
==========
It's possible to create up to 253 tablespaces.
Operators to move an index or table to a tablespace require an exclusive database lock.
We have plans to create functionality to move blobs to separate tablespaces.