Initializing data directory for postgresql not successful - postgresql

I tried to initialize the postgresql data directory, and I get this error :
[postgres#vix-db1-1 ~]$ /usr/pgsql-9.5/bin/initdb --nodename=vix-db1-1 -D /var/lib/pgsql/9.5/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory /var/lib/pgsql/9.5/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
creating template1 database in /var/lib/pgsql/9.5/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
creating cluster information ... FATAL: syntax error at or near "-" at character 16
STATEMENT: CREATE NODE vix-db1-1 WITH (type = 'coordinator');
child process exited with exit code 1
initdb: removing data directory "/var/lib/pgsql/9.5/data"
It says “FATAL: syntax error at or near “-” at character 16”; but the hostname has to have the “-” due to new server version.
I tried doing it without nodename, but for that another problem :
[postgres#vix-db1-1 ~]$ /usr/pgsql-9.5/bin/initdb -D /var/lib/pgsql/9.5/data
initdb: Postgres-XL node name is mandatory
Try "initdb --help" for more information.
[postgres#vix-db1-1 ~]$
How do I resolve this?

You must be using some fork of PostgreSQL, since initdb does not have a --nodename parameter.
Whoever wrote that fork didn't do a very good job, since they forgot to properly escape special characters somewhere. You should report that as a bug to the software vendor.

#anaigini I'll move the comment to answer since it worked:
You may have to pass the name in quotes, so that it substitutes in the
query, using --nodename='"vix-db1-1"'. The outer single-quotes will be
used by the shell, leaving the inner double-quotes for the query.

Related

multiple entries for synchronous_standby_names

Trying to achieve sync streaming to barman server and i need to add an entry to postgresql.conf for this parameter, which already has an entry and tried a few variations but does not work. Any ideas? Also tried '&&' but in vain
synchronous_standby_names='ANY 1 (*)',barman-wal-archive
2022-06-10 16:50:54.272 BST [11241-43] # app= LOG: syntax error in
file "/var/lib/pgsql/13/data/postgresql.conf" line 22, near token ","
2022-06-10 16:50:54.272 BST [11241-44] # app= LOG: configuration file
"/var/lib/pgsql/13/data/postgresql.conf" contains errors; no changes
were applied
The syntax you are using is not valid, and you won't be able to specify that Barman should be kept synchronous and any one of the others. The best you can do is
synchronous_standby_names = 'FIRST 2 ("barman-wal-archive", standby1, standby2, standby3)'
(You have to double quote all names that are not standard SQL identifiers, for example if they contain -.)
Then PostgreSQL will always keep Barman synchronized, as well as the first available standby server. But that won't have transactions fail if Barman is not available, which seems to be what you want.
Keep just
synchronous_standby_names='ANY 1 (*)'
and set
synchronous_commit = on
or
synchronous_commit = remote_write

could not access file "pg_wait_sampling": No such file or directory postgresql

after I use the following command then I cannot relogin postgresql
alter system set shared_preload_libraries = 'pg_wait_sampling';
exit trying login again. Then error happens. The following is error code:
2022-03-15 11:35:30.726 IST [975] FATAL: could not access file "pg_wait_sampling": No such file or directory
2022-03-15 11:35:30.727 IST [975] LOG: database system is shut down
pg_ctl: could not start server
Examine the log output.
postgresql version: 14.2. system: wsl ubuntu.
in conf file /etc/postgresql/14/main/postgresql.conf":
#shared_preload_libraries='' #(change requires restart)
According to PostgreSQL document alter command store in postgresql.auto.conf file.
You have to change this file and remove pg_wait_sampling form this file

Many syntax and permissions errors on postgres sql dump import

I am trying to import a .sql database dump into my postgres 9.6.1. I've tried in command line as well as the Postico GUI but get a ton of errors (like thousands of lines of errors) on import.
The SQL dump is from a coworker running postgres 9.4.5 and the SQL looks valid.
My Postgres Version:
PostgreSQL 9.6.1 on x86_64-apple-darwin, compiled by
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc.
build 5658) (LLVM build 2336.11.00), 64-bit
I've tried the following imports:
psql -U postgres dbname < ~/Desktop/dbname_local_db_20161122.sql
Then logging in and trying it:
psql -U postgres dbname
dbname=# \i ~/Desktop/dbname_local_db_20161122.sql
Errors: (there are way more than this)
Password for user postgres:
SET
SET
SET
SET
SET
SET
CREATE EXTENSION
COMMENT
ERROR: schema "public" does not exist
ERROR: extension "citext" does not exist
ERROR: schema "public" does not exist
ERROR: extension "pg_trgm" does not exist
SET
ERROR: function "add_session_metric" already exists with same argument types
ERROR: role "myrole" does not exist
ERROR: function "session_metrics_partition_creation" already exists with same argument types
ERROR: role "myrole" does not exist
ERROR: function "session_metrics_partition_function" already exists with same argument types
ERROR: role "myrole" does not exist
SET
SET
ERROR: permission denied to create "pg_catalog.messages"
DETAIL: System catalog modifications are currently disallowed.
ERROR: relation "messages" does not exist
ERROR: permission denied to create "pg_catalog.Message_id_seq"
DETAIL: System catalog modifications are currently disallowed.
ERROR: relation "Message_id_seq" does not exist
ERROR: relation "Message_id_seq" does not exist
ERROR: permission denied to create "pg_catalog.sessions_users"
invalid command \N
invalid command \N
invalid command \N
invalid command \N
invalid command \N
invalid command \.
ERROR: syntax error at or near "2"
LINE 1: 2 hello 3 1 2015-11-12 09:25:14.646-07 2015-11-12 09:25:14.64...
ERROR: syntax error at or near "1"
LINE 1: 1
^
ERROR: relation "external_session_info_sessions" does not exist
invalid command \.
ERROR: syntax error at or near "2528"
LINE 1: 2528 1
^
invalid command \.
ERROR: relation "feedback_id_seq" does not exist
LINE 1: SELECT pg_catalog.setval('feedback_id_seq', 1, false);
Like I said, the SQL file looks valid. I've checked for compatibility issues from 9.4.5 to 9.6.1 but don't see any.
I do see PERMISSION DENIED but I am running the command as user postgres which has super user permissions:
First, the recommended way is to use pg_dump from the higher (target) database version to create the dump, because that version of pg_dump knows about incompatible changes that happened since and can create a dump that will restore correctly.
Some of the errors are normal if you restore a dump into a database that already has objects with the same names in it; often that is a sign that the dump should actually have been created with pg_dump -C to include a CREATE DATABASE statement.
However, your SQL script seems seriously messed up, and I doubt that it is an unmodified dump of a 9.4.5 database.
pg_dump will never dump any objects in pg_catalog. This schema can only contain system objects which are not included in a dump (they are created by CREATE DATABASE), and as you have seen, not even a superuser may create an object in that schema (unless allow_system_table_mods is on, which it really shouldn't be).

Can not set `task_executor_type`

When I trying to put citus cluster configuration value into postgresql.conf file:
citus.task_executor_type = "task-tracker"
I got the error:
service postgresql restart
Error: Invalid line 637 in /etc/postgresql/9.5/main/postgresql.conf: »citus.task_executor_type = "task-tracker"«
* No PostgreSQL clusters exist; see "man pg_createcluster"
Tell me please how can I set this configuration value by default?
I am not ready to run SET citus.task_executor_type TO "task-tracker" for each connection.
I am not sure but you are using double quote instead of single quote and this can be the problem. Try using single quote like:
citus.task_executor_type = 'task-tracker'

PostgreSQL timezone error with DbSchema

I want to setup my postgreSQL server to 'Europe/Berlin' but having an error:
SET time zone 'Europe/Berlin';
ERROR: invalid value for parameter "TimeZone": "Europe/Berlin"
But the real issue is with DdbSchema, when I want to connect to my DB i've got the error
FATAL: invalid value for parameter "TimeZone": "Europe/Berlin"
DbSchema works when I connect to my local db but not with my NAS (Synology) DB.
Any idea ?
Found a way to solve the problem:
You have to start java with the proper time zone.
In my case, my server is GMT, so i had to add the args -Duser.timezone=GMT
For DbSchema, edit the file DbSchema.bat or DbSchema.sh
Find the declaration of SWING_JVM_ARGS
Add the argument -Duser.timezone=GMT a the end of the line
Start DbSchema with this script DbSchema.bat or DbSchema.sh
I think your solution is only a workaround for the actual problem concerning the zoneinfo on the synology diskstation.
I got exactly the same error when trying to connect to the postgres database on my diskstation. The query select * from pg_timezone_names; gives you all timezone names postgresql is aware of.
There are 87 entries all starting with "Timezone":
name | abbrev | utc_offset | is_dst
------------------------+--------+------------+--------
Timezone/Kuwait | AST | 03:00:00 | f
Timezone/Nairobi | EAT | 03:00:00 | f
...
The configured postgres timezonesets contain much more entries, so there must be another source that postgres is building this view of at startup. I discovered that there is a compile-option --with-system-tzdata=DIRECTORY that tells postgres to obtain its values from system zoneinfo.
I looked in /usr/share/zoneinfo and found one subdirectory called Timezone with exactly 87 entries. And there obviously was no subdirectory called Europe (with a timezone file called Berlin). I did not quickly find a solution for the diskstation to update the tzdata automatically or manually by unpacking tzdata2016a.tar.gz and making (make not found...). As a quickfix I copied the Berlin timezone file from another linux system and the problem was solved, so that I now can connect via java/jdbc using the correct timezone "Europe/Berlin"!