How can I change the postgres random_page_cost on Heroku? - postgresql

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.

Related

How to change effective_io_concurrency in 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

Alter TYPE RENAME VALUE works in Postgres 10 but not in Postgres 9.6?

I am using Postgres 10.3.
Based on this question, I use:
ALTER TYPE name RENAME VALUE attribute_name TO new_attribute_name
to rename an enum value.
But I need a solution that works with Postgres 9.6 that does not require updating pg_enum manually because it needs permissions that I don't have.
There is no supported way to rename an enum value in PostgreSQL 9.6.
Directly modifying pg_enum is something you should not only rule out because of permission issues, but also because directly messing with the system catalogs is dangerous and may destroy your data.
You should use enums with care. They are only good if they never need to be modified. If there is a chance that the enum values won't be immutable, use a lookup table instead.

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.

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

Is it safe to change Collation on Postgres (keeping encoding)?

I have a Postgres 9.3 database which, by mistake, has been set to:
but I need it to be:
Since the Encoding doesn't change, it is safe to dump the DB and restore it later (see here) to a database with the new Collation / Character type?
Perfectly safe -- the collation is just telling Postgres which set of rules to apply when sorting text.
You can even set it dynamically on a query basis in the order by clause, and should be able to alter it without needing to dump the database.