How to change effective_io_concurrency in Postgresql - postgresql

I'm trying to change these two parameters (random_page_cost and effective_io_concurrency) in my Postgresql 12 database. For the first one I found this command :
alter database mydb set random_page_cost=1.1;
However, for the second I couldn't find how to do it. I thought about changing the postgres.conf file but it's not there at all. Can I add it ? or is there a similar command to random_page_cost ?

The syntax is as follows:
ALTER TABLESPACE mytablespace SET effective_io_concurrency = 1;
Replace mytablespace with your specific tablespace and choose another number for effective_io_concurrency.
Corresponding documentation for V10:
https://www.postgresql.org/docs/10/runtime-config-resource.html#:~:text=effective_io_concurrency
https://www.postgresql.org/docs/10/sql-altertablespace.html

Related

SET/RESET command in ALTER DATABASE is not supported

Encountered this issue when trying to modify the search_path to my new Redshift db.
Presently, I've migrated the contents of my MySQL db into a redshift cluster via AWS' Data Migration Service. The data was imported into a schema lets call my_schema. When I try to execute queries against the cluster it requires me to prefix table names with the schema name
i.e.
select * from my_schema.my_table
I wanted to change the setup so that I can reference the table directly without needing the prefix. After a bit of looking around I found out that this was possible by modifying the search_path attribute.
First I tried doing this by running
set search_path = "$user", my_schema;
This appeared to work but then I realized that this was simply setting my_schema as the default schema in the context of the current session, I wanted it set on a database level. I found several sources saying that the way to do this was to use the alter command like so...
alter database my_db set search_path = "$user", public, my_schema
However, running this command results in the following error which somehow shows up in 0 google results:
SET/RESET commmand in ALTER DATABASE is not supported
I'm pretty baffled by how the above error hasn't ever had a post made about it but I'm also pretty interested in figuring out how to resolve my initial issue of setting a global default schema for my redshift cluster.
ALTER DATABASE SET is not supported in Redshift. However you can SET/RESET configuration parameters at USER level using the ALTER USER SET SEARCH_PATH TO <SCHEMA1>,<SCHMEA2>;
Please check: http://docs.aws.amazon.com/redshift/latest/dg/r_ALTER_USER.html
http://docs.aws.amazon.com/redshift/latest/dg/r_search_path.html
When you set the search_path to <SCHEMA1>,<SCHMEA2> in db1 for a user it is not for just current session, it will be set for all future sessions.

How can I change the postgres random_page_cost on Heroku?

On a Heroku-managed instance of postgres the default value for random_page_cost is 2.0. I'd like to change the value, but don't see a way to do so. How can I change that value?
You can alter the database to get the number you want.
alter database mydb set random_page_cost=1.4;
It turns out this can be done at the connection level, with no change required to the database.

Getting my postgresql db version?

On SQlite I could do a query for PRAGMA user_version; and I could set the version if need be too. Is there anything in postgres that could do the same thing?
I tried select version() but that gets the literal version of postgres, and not a custom set version.
As an update: I researched commenting on databases. Perhaps this could be solution... commenting docs
You can set a custom configuration parameter. The parameter name must contain a dot, e.g.:
set my.version to 4;
select current_setting('my.version') as version;
version
---------
4
(1 row)
A parameter defined in this way is local to the current session. If you want to define a default value for the parameter for all sessions you can add it to the configuration file postgresql.conf (for all databases in the server). Alternatively, it is possible to set the default value for a database in the command:
set my.version to 4;
alter database my_database set my.version from current;
See also:
Setting Parameters
Customized Options
ALTER DATABASE

Failed to enable db2gse spatial commands

I created a database called mapdata in which I will create a table called school. One of the datatypes for one of the columns is db2gse.ST_Point. I have tried creating the table school with the column with that datatype but it gave me an error saying db2gse.ST_Point is an undefined name. So then I figured I had to enable the spatial commands using this statement:
db2se enable_db mapdata
But that gives me error as well. It says a temporary table space could not be created because there is no available system temporary table space that has a compatible page size.
How can I resolve this problem?
If you take a look at the db2se enable_db page in the manual you will probably notice this, among other things:
Usage notes
Ensure that you have a system temporary table space with a page size of 8 KB or larger and with a minimum size of 500 pages. This is a requirement to run the db2se enable_db command successfully.
The error message tells you that there is no such tablespace. I suspect that your database also does not have a matching bufferpool.
To create a system temporary tablespace you might use the following commands (assuming your database is configured with automatic storage):
db2 "create bufferpool bp8k pagesize 8 k"
db2 "create system temporary tablespace tmpsys8k pagesize 8 k bufferpool bp8k"

PostgreSQL - How to change tmp directory?

I am running PostgreSQL on Windows 8 using the OpenGeo Suite. I'm running out of disk space on a large join. How can I change the temporary directory where the "hash-join temporary file" gets stored?
I am looking at the PostgreSQL configuration file and I don't see a tmp file directory.
Note: I am merging two tables with 10 million rows using a variable text field which is set to a primary key.
This is my query:
UPDATE blocks
SET "PctBlack1" = race_blocks."PctBlack1"
FROM race_blocks
WHERE race_blocks.esriid = blocks.geoid10
First, make sure you have an index on these columns (of both tables). This would make PostgreSQL use less temporary files. Also, set the GUC work_mem to as high as possible, to make PostgreSQL use more memory for operations like this.
Now, if still need, to change the temporary path, you first need to create a tablespace (if you didn't do it already):
CREATE TABLESPACE temp_disk LOCATION 'F:\pgtemp';
Then, you have to set the GUC temp_tablespaces. You can set it per database, per user, at postgresql.conf or inside the current session (before your query):
SET temp_tablespaces TO 'temp_disk';
UPDATE blocks
SET "PctBlack1" = race_blocks."PctBlack1"
FROM race_blocks
WHERE race_blocks.esriid = blocks.geoid10
One more thing, the user must have CREATE privilege to use this:
GRANT CREATE ON TABLESPACE temp_disk TO app_user;
I was unable to set the F:/pgtemp directory directly in PostgreSQL due to a lack of permissions.
So I created a symlink to it using the windows command line "mklink /D" (a soft link). Now PostgreSQL writes temporary files to c:\Users\Administrator.opengeo\pgdata\Administrator\base\pgsql_tmp they get stored on the F: drive.