When changing parameter at database level.
Example:
alter database db1 set idle_in_transaction_session_timeout to 0;
Is there a view that list the values of the parameters defined specifically for a database?
No view, but the data can be found in the system catalog pg_catalog.pg_db_role_setting. In psql, you can see them with the command \drds.
Related
I have a Postgres database in Cloud SQL and would like to utilize the pg_trgm extension to do similarity searches. However, the default threshold parameters are not sensitive enough in my use case so they should be altered.
The problem is that Cloud SQL does not provide database flags for either pg_trgm.similarity_threshold or pg_trgm.word_similarity_threshold and the database users do not have the privileges to alter the user or database:
postgres=> ALTER ROLE postgres SET pg_trgm.similarity_threshold = 0.1;
ERROR: permission denied to set parameter "pg_trgm.similarity_threshold"
postgres=> ALTER DATABASE postgres SET pg_trgm.similarity_threshold = 0.1;
ERROR: permission denied to set parameter "pg_trgm.similarity_threshold"
Is there any other way to alter these parameters?
Can you do the straightforward SET pg_trgm.similarity_threshold = 0.1;? You would have to repeat it in every session, so maybe incorporate it into your connection sub.
For similarity_threshold, you can use the function set_limit unless Google has also disabled that. You would also have to set it this way in each session, though. There is no alternative way to set word_similarity_threshold, though, unless Google has invented one.
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.
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
when i use (pg_dump -f backup.sql mydb), the schema name are not included. How to dump that will output also the scheme name(personal). see example below
Output : ALTER TYPE basicinfo OWNER TO postgres;
// note : basicinfo is the name of the table
Expected Output : ALTER TYPE personal.basicinfo OWNER TO postgres;
any ideas?
Global Database properties such as OWNER etc. are always given with SCHEMA names in a pg_dump output.
However, for non-global database objects, as far as I know, there isn't any way to get SCHEMA names prepended to all the database objects. The way the script works is that it sets the SET search_path before-hand all Schema specific database objects... which is more efficient and has the same effect.
In case you are trying to parse an pg_dump output to extract a given SQL line that works independently, you may have to also parse the nearest-preceding SET search_path line and execute that before executing the target line (for e.g. ALTER TYPE) to have the desired effect.
You cant do that using pg_dump directly.
Try to use different tools, They have different implementation for exporting PostgreSQL database.
Here are list of tools:
phpPgAdmin - http://sourceforge.net/projects/phppgadmin
AnySQL Maestro - http://www.sqlmaestro.com/products/anysql/maestro/
DBeaver - http://dbeaver.jkiss.org/
All refence: https://wiki.postgresql.org/wiki/Community_Guide_to_PostgreSQL_GUI_Tools
I want to create a test environment where the basic underlying postgres database is overlain with an instance-localized private view, such that all queries from a specific set of processes go through the private view while other (potentially concurrent or merely subsequent) processes would remain unaffected.
I think I can do something like this using the search_path mechanism, but it's not clear if I can do that transparently (e.g., without having each application execute some set of SQL setup for each connection). For example, is there something I could set as an environment variable saying "use this search_path" and have every process that I start thereafter see that and use the same private table instances?
If it matters, the processes are all going through the C++ adapter, libpqxx, to access the database.
Thanks,
Jeff
If every instance has a separate database user role, you can simply create a schema with the same name as the user and it'll use it -- without any change to configuration:
myuser=> show search_path;
search_path
--------------
"$user",public
(1 row)
myuser=> create schema myuser;
CREATE SCHEMA
myuser=> create table foo(i int);
CREATE TABLE
myuser=> \d foo
Table "myuser.foo"
Column Type Modifiers
------ ------- ---------
i integer
If you want to have different names for users and schemas, you can configure it for each user manually:
ALTER USER foo SET search_path=foo_schema;
You can configure the default search path for all connections in the postgre configuration file.
See http://www.postgresql.org/docs/9.0/static/runtime-config-client.html#RUNTIME-CONFIG-CLIENT-OTHER
If each connection needs some custom search path based on who the user is you will have to do that in your code and issue a SET search_path TO x,y,z;for each connection.
Another option that comes to mind is using stored functions and have them use dynamic sql to query from different schemas based on who the caller is. You would have to maintain a table or the more evil of the two "hard code" the user/schema mappings into the stored functions that the stored function would use.