I am trying to create a tablespace in postgres on a mounted volume, but I am getting ownership problems.
I am doing something like:
sudo mkdir /mnt/postgresql
sudo mkdir /mnt/postgresql/space
sudo chown -R postgres:postgres /mnt/postgresql
Then, as the posgres superuser (sudo -u postgres psql), I am using the following command :
CREATE TABLESPACE myspace LOCATION '/mnt/postgresql/space';
I get the following error:
ERROR: could not set permissions on directory "/mnt/postgresql/space": Operation not permitted
I am using psql 9.2.24 with CentOS Linux release 7.7.1908.
Why the PostgreSQL system user could not set permissions on directory that it is owned ?
Related
I am trying to install Apache age and Postgres from source code but i am not able to start postgres Server
`
The files belonging to this database system will be owned by user "faruukh".
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.
initdb: could not access directory "/usr/local/pgsql/bin/psql": Not a directory
faruukh#ubuntu:~$ sudo chown -R farrukh /usr/local/pgsql/
chown: invalid user: ‘farrukh’
faruukh#ubuntu:~$ sudo chown -R faruukh /usr/local/pgsql/
faruukh#ubuntu:~$ which psql
/usr/local/pgsql/bin//psql
faruukh#ubuntu:~$ ls /usr/local/pgsql/bin/
clusterdb data ecpg pg_basebackup pg_controldata pg_dumpall pg_recvlogical pg_rewind pg_upgrade postgres reindexdb
createdb dropdb initdb pgbench pg_ctl pg_isready pg_resetwal pg_test_fsync pg_verify_checksums postmaster vacuumdb
createuser dropuser pg_archivecleanup pg_config pg_dump pg_receivewal pg_restore pg_test_timing pg_waldump psql
faruukh#ubuntu:~$ export PATH=/usr/local/pgsql/bin//psql:$PATH
faruukh#ubuntu:~$ export PGDATA=/usr/local/pgsql/bin//psql/data
faruukh#ubuntu:~$ sudo chown -R faruukh /usr/local/pgsql/
faruukh#ubuntu:~$ initdb
The files belonging to this database system will be owned by user "faruukh".
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.
initdb: could not access directory "/usr/local/pgsql/bin/psql/data": Not a directory
faruukh#ubuntu:~$ sudo initdb
sudo: initdb: command not found
faruukh#ubuntu:~$ export PGDATA=/usr/local/pgsql/bin//psql/data
faruukh#ubuntu:~$
faruukh#ubuntu:~$
faruukh#ubuntu:~$
faruukh#ubuntu:~$
faruukh#ubuntu:~$
faruukh#ubuntu:~$ which psql
/usr/local/pgsql/bin//psql
faruukh#ubuntu:~$ pg_ctl
pg_ctl pg_ctlcluster
faruukh#ubuntu:~$ pg_ctl
pg_ctl pg_ctlcluster
faruukh#ubuntu:~$ pg_ctl
pg_ctl pg_ctlcluster
faruukh#ubuntu:~$ pg_ctl start log -l
pg_ctl: option requires an argument -- 'l'
Try "pg_ctl --help" for more information.
faruukh#ubuntu:~$ pg_ctl
pg_ctl: no operation specified
Try "pg_ctl --help" for more information.
faruukh#ubuntu:~$
`
```
```[error][1]
Tried following commands
cd postgresql-12.0
which psql
ls /usr/local/pgsql/bin/
export PATH=/usr/local/pgsql/bin/:$PATH
export PGDATA=/usr/local/pgsql/bin/data
sudo chown -R faruukh /usr/local/pgsql/
Try:
su -l <username> to switch user account and then run initdb -D <path to where new db cluster should be stored>
For me which psql gives /usr/bin/psql.
To start postgres SQL: sudo systemctl start postgresql#12-main (if pg version 12 is installed)
To check if postgres is running: service postgresql status
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor pr>
Active: active (exited) since Sat 2023-02-18 23:01:05 IST; 7min ago
To get into postgres shell: sudo su - postgres, and type the password.
To get into psql shell: psql -p <port>.
This worked for me, try the following commads :
su --login faruukh
cd /usr/local/pgsql/bin/
./initdb -D /usr/local/pgsql/bin/psql/data
Here's the reference for initdb
I reproduced the error that you encountered:-
~/Downloads$ initdb
The files belonging to this database system will be owned by user "capnspek".
This user must also own the server process.
The database cluster will be initialized with locale "en_IN".
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.
initdb: could not access directory "/usr/local/pgsql/bin/psql/data": Not a directory
Adding a ./data at the end of the command successfully initializes the database cluster.
~/Downloads$ initdb ./data
The files belonging to this database system will be owned by user "capnspek".
This user must also own the server process.
The database cluster will be initialized with locale "en_IN".
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 ./data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... Asia/Kolkata
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D ./data -l logfile start
Hopefully, that solves your issue.
Read more about initdb here.
Follow the documentation from here.
I am trying to set up PostgreSQL in Linux, but the following error comes up:
[postgres#kibearch ~]$ initdb --pgdata=/var/lib/pgsql/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/data ... initdb: error: could not create directory "/var/lib/pgsql": Permission denied
If I try to use sudo initdb --pgdata=/var/lib/psql/data/, it says that initdb can not be used with sudo.
Here are the steps I did:
sudo pacman -S postgresql
Switched to user postgres user using this command: su - postgres
Tried to initialize the server but the aforementioned error showed up
What can I do?
As root:
mkdir /var/lib/pgsql
chown postgres /var/lib/pgsql
As postgres:
initdb --pgdata=/var/lib/pgsql/data
I have installed postgresql on ubuntu using:
$ sudo apt install postgresql
Now, I have a series of sql queries I would like to fire to create schemas and users and tables etc. I have put those queries in a .sql file as below:
$ sudo nano postgressetup.sql
CREATE SCHEMA schma;
CREATE USER a2i WITH PASSWORD 'password';
GRANT CONNECT ON DATABASE postgres TO schma;
This file has all the queries. I tried something like:
$ psql -U postgres -d postgres -a -f postgressetup.sql
and received error:
psql: FATAL: Peer authentication failed for user "postgres"
I want to know the way I can execute this .sql file.
Note: I've just installed postgres and no further operation is done on it. Any help is appreciated.
You can use the following command explicitly providing db context user
sudo -u postgres psql -U postgres -d postgres -a -f postgressetup.sql
I have problem connecting to database. I recive message that role "Darko" does not exists. This is the sequence of my commands:
/usr/local/pgsql/bin/pg_ctl start -D /usr/local/pgsql/data -l logfile
Server starting /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data The files belonging to this database system will be owned by user "darko".
This user must also own the server process.
The database cluster will be initialized with locales COLLATE: en_US.UTF-8 TYPE: en_US.UTF-8 MESSAGES: en_US.UTF-8 MONETARY: hr_HR.UTF-8 NUMERIC: hr_HR.UTF-8 TIME: 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. initdb: directory "/usr/local/pgsql/data" exists but is not empty
If you want to create a new database system, either remove or empty the directory "/usr/local/pgsql/data" or run initdb with an argument other than "/usr/local/pgsql/data". /usr/local/pgsql/bin/psql psql:
FATAL: role "darko" does not exist
You're trying to initialize Postgres cluster (main directory where all your Postgres data and logs will be stored) in "/usr/local/pgsql/data" directory.
Create another directory, anywhere and pass full path to it to -D option of initdb.
It will initialize your Postgres cluster.
During this process, a default database role will be created. If you run initdb under your regular OS user ("darko") -- it will create database user with the same name. But usually people run posgres tools (including initdb) under a separate OS user, "postgres" -- and if you will do it (like "sudo -u postgres initdb -D ..."), initdb will create database role "postgres" instead. (BTW, in Postgres terminology, database user and database role are the same things).
Then, once initbd has successfully created your Postgres cluster, you can check it using "ls" -- directory must contain subdirectories such as "base", "global", "pg_xlog", config files, etc.
Then you need to run Postgres, it's done using pg_ctl command, and you need to pass path to your cluster, again with -D option:
pg_ctl -D /path/to/cluster
If it runs successfully, open another terminal tab/window and try to connect using psql and corresponding database role (either "darko" or "postgres", based on your previous decision):
psql -U darko template1
"template1" is a database name which is always present, it serves as a template for all future databases you'll create.
Also, before you try to start Postgres with pg_ctl, it's worth to check if you have already some Postgres running:
ps ax | grep postgres
-- if you have another Postgres running, you can shut it down using "pg_ctl stop" with corresponding -D option pointing to the proper cluster directory.
Example (Ubuntu):
$ ps ax | grep postgres | grep D
21996 ? S 23:37 /usr/lib/postgresql/9.6/bin/postgres -D /var/lib/postgresql/9.6/main -c config_file=/etc/postgresql/9.6/main/postgresql.conf
To stop it gracefully, just run:
/usr/lib/postgresql/9.6/bin/pg_ctl -D /var/lib/postgresql/9.6/main stop
initdb is a tool used to create a cluster (see PostgreSQL documentation for cluster definition in this context). It seems your allready did that as your directory isn't empty. Don't do it anymore.
Then, you're trying to connect with psql. By default, it's trying a socket connection with the same name for database user as your OS user. As you didn't create a role named 'darko', it fails.
What you have to do is trying to connect as postgres user. Try this to connect:
sudo -u postgres psql
You should be abble to connect with that line (assuming you didn't change the pg_hba.conf file) and then you should be abble to create your users and databases.
Here's the documentation page for psql.
I have been trying to set up vagrant but I am getting this error.
I will list out my installation method. Please suggest changes where you feel they are needed.
-Installed virtual box
sudo apt-get install virtual box
-Downloaded .deb package from vagrant website
-Installed it using
sudo dpkg -i (package_name)
-then I selected the vagrant folder in the fullstack folder and
vagrant up
vagrant ssh
then I did :
vagrant#vagrant-ubuntu-trusty-32: cd /vagrant/forum
vagrant#vagrant-ubuntu-trusty-32:/vagrant/forum$ sudo apt-get install postgresql-client-common
vagrant#vagrant-ubuntu-trusty-32:/vagrant/forum$ sudo apt-get install postgres-xc-client
Then finally:
vagrant#vagrant-ubuntu-trusty-32:/vagrant/forum$ psql
psql: FATAL: role "vagrant" does not exist
You need to change to the postgres user and give vagrant superuser access.
sudo su - postgres
createuser vagrant -s
exit # exit from postgres user back into vagrant
You can do everything with with vagrant now.
This is happening because there is no role specified in postgres. When there is no role specified, it tries to use the username of the account as the default role and hence your error. So, now, you could either create a role in postgres for the vagrant user or just use the postgres user itself.
So, first, login with the postgres user:
psql -U postgres
then, create a role for the user vagrant
CREATE ROLE vagrant LOGIN;
In case, if you want it with a password, use:
CREATE USER vagrant WITH PASSWORD 'password';
or
CREATE ROLE vagrant WITH LOGIN PASSWORD 'password';
CREATE USER is the same as CREATE ROLE with the exception that USER implies LOGIN.
Source
You are trying to connect to postgresql using vagrant user. In this case, postgresql y looking for the corresponding vagrant role (if not specified, the default role for a user is it's username). However, looks like there is no such role created.
You can create the role, or try for example a login using the postgres user:
vagrant#vagrant-ubuntu-trusty-32:/vagrant/forum$ psql -U postgres
You can also specify the databasename you want to connect to:
vagrant#vagrant-ubuntu-trusty-32:/vagrant/forum$ psql -U postgres -d DATABASENAME
1)First exit the vagrant prompt
exit
2) Halt the vagrant instance
vagrant halt
3)Destroy the vagrant instance
vagrant destroy
4)Create a new instance
vagrant up
This might solve it. It atleast did for me.(Tried it)