Altering tablespace for partitioned table in Postgres - postgresql

In my database i have a partitioned table with name 'record_partitioned' on PostgreSQL 11.2.
i want to change its tablespace to a new tablespace 'fast_ssd' so all new dervied tables from this table be in 'fast_ssd' tablespace.
when i try to alter tablespace to 'fast_ssd'.
alter table record_partitioned set tablespace fast_ssd;
i see:
ALTER TABLE
but it seems nothing happened! i check tablespace like this:
SELECT tablespace,tablename FROM pg_tables where tablename='record_partitioned';
and output is:
tablespace | tablename
------------+--------------------
| record_partitioned
tablespace does not change.

There is no way to do this for a partitioned table. You'll have to add an explicit TABLESPACE clause whenever you create a partition.
An alternative is to set the default_tablespace parameter, but that would affect all other tables too.

Related

Setting autovacuum on partitioned tables in Postgres 11

I'm trying to adjust autovacuum settings on a partitioned table, on PostgreSQL 11.
e.g:
# create table test (ts timestamp) partition by range (ts);
CREATE TABLE
# alter table test set (autovacuum_analyze_scale_factor = 0.1);
ERROR: unrecognized parameter "autovacuum_analyze_scale_factor"
Is it possible to alter such settings on partitioned tables?
It seems that you can only set parameters on table partitions rather than on parent table.
postgres=# create table test (ts timestamp) partition by range (ts);
CREATE TABLE
postgres=# create table test_2018 partition of test for values from ('2018-01-01 00:00:00') to ('2018-12-31 23:59:59');
CREATE TABLE
postgres=# alter table test_2018 set (autovacuum_analyze_scale_factor = 0.1);
ALTER TABLE
postgres=# alter table test set (autovacuum_analyze_scale_factor = 0.1);
ERROR: unrecognized parameter "autovacuum_analyze_scale_factor"
postgres=#

Access table data in local PostgreSQL

I installed PostgreSQL on my local machine and create the table in my own database.
Database properties looks like
Name: MyDB
Tablespace: pg_default
Default tablespace: pg_default
System database? No
And my table properties looks like
Name: mytable
Tablespace: pg_default
System table? No
But when I try to do
select * from mytable;
I am getting
ERROR: relation "mytable" does not exist
Create table statement
create table mytable (
.....
);
Any suggestion?
I had the same issue, and clearly, if the create statements were including double quotes around the tables names, you have to use them too in your select statement to see the table (granted that you are the proper user with the proper privileges on tables). (and it's case sensitive even in Windows...)

How to apply PostgreSQL UNLOGGED feature to an existing table?

Can I ALTER an existing table to be UNLOGGED?
PostgreSQL 9.5+ allows setting an existing table as LOGGED / UNLOGGED with the ALTER TABLE command... detailed better here.
For e.g.
ALTER TABLE table_test SET LOGGED;
ALTER TABLE table_test SET UNLOGGED;
The following solution is for PostgreSQL versions<=9.4:
You can do:
create unlogged table your_table_alt as
select * from your_table;
Then:
drop table your_table;
alter table your_table_alt rename to your_table;

Where will the tablespace be stored?

I am creating a table with tablespace:
CREATE TABLE SALARY.....
IN ACCOUNTING INDEX IN ACCOUNT_IDX
Where will the Accounting and Account_IDX be created?
The script that you have above will create SALARY in the ACCOUNTING tablespace, with indexes for that table in ACCOUNT_IDX tablespace.
The ACCOUNTING and ACCOUNT_IDX tablespaces need to be created in a separate script that has CREATE TABLESPACE statements.
If you look at the syntax for CREATE TABLESPACE, the USING part of the statement will tell DB2 where to put the files for the tablespace.
DB2 Create Tablespace Reference

How to delete a user in Oracle 10 including all it's tablespace and datafiles

When I give the command to drop a user i.e. DROP USER 'username' cascade,
Does it deletes all the tablespace and datafiles used by that particular user.
If not, what is the command to delete all the tablespace / datafiles / disk space that were used by that particular user.
After dropping the user, you need to, for each related tablespace, take it offline and drop it. For example if you had a user named 'SAMPLE' and two tablespaces called 'SAMPLE' and 'SAMPLE_INDEX', then you'd need to do the following:
DROP USER SAMPLE CASCADE;
ALTER TABLESPACE SAMPLE OFFLINE;
DROP TABLESPACE SAMPLE INCLUDING CONTENTS;
ALTER TABLESPACE SAMPLE_INDEX OFFLINE;
DROP TABLESPACE SAMPLE_INDEX INCLUDING CONTENTS;
DROP USER---->
DROP USER USER_NAME CASCADE;
DROP TABLESPACE---->
DROP TABLESPACE TABLESPACE_NAME INCLUDING CONTENTS AND DATAFILES;
You can check which table space is used by which user with the following query.
SELECT USERNAME, DEFAULT_TABLESPACE FROM DBA_USERS;
You can also see the list of table spaces by looking at the following tables
DBA_TABLESPACES
USER_TABLESPACES