First I use homebrew and install postgresql and I get this success message:
==> Summary 🍺 /usr/local/Cellar/postgresql/9.2.2: 2819 files, 39M, built in 68 seconds
Then I need to run this command:
initdb `brew --prefix`/var/postgres -E utf8
But this is the message I get:
What should I do with this?
Also running on OSX 10.8.2
The files belonging to this database system will be owned by user
"JonyIve". This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default text search configuration will be set to "english".
initdb: directory "/usr/local/var/postgres" exists but is not empty If
you want to create a new database system, either remove or empty the
directory "/usr/local/var/postgres" or run initdb with an argument
other than "/usr/local/var/postgres".
Assuming this is a new installation and not a re-installation I think solving your problem is as simple as:
initdb `brew --prefix`/var/postgres/data -E utf8
Typically the data directory is called "data' and is underneath the postgresql home directory. this allows for the possibility of sharing log file access and the like.
If you know that you can do this without breaking anything, another option is always just to remove the directory as per the message
remove or empty the directory "/usr/local/var/postgres"
Via
rm -rf /usr/local/var/postgres
Related
I've been given a project to extract data from a PostgreSQL database. I've no previous experience with PostgreSQL but the project I have is to bug fix existing code, so all the logic to connect to the engine and get data is already in place.
The problem I have is the database has been given to me in the form of the folders and files straight from the source HDD, not a backup (which isn't going to happen so "Get the customer to give you a backup instead isn't an option here).
The folders also contained the actual PostgreSQL binaries so I looked a the version (9.4.14) and downloaded the nearest (9.4.18) from the PostgreSQL site and installed it. Now all I have to do is some how is to get it to look at my given data files.
I tried the obvious of copying the contents of the data folder into the installed data folder but after the PostgreSQL service won't start.
I did find a option in the conf file:
#data_directory = 'ConfigDir'
I changed this to:
data_directory = 'C:\customer\data'
But again the service won't start after this.
The data directory used by the service is defined through the service command line which overwrites any property defined in postgresql.conf.
You need to re-create the service in order to change the data directory, e.g.:
Remove the service:
pg_ctl -unregister -N postgresql-9.1
postgresql-9.1 is the "real" name of the service, not the "Display Name". You can see that in the properties of the service inside the "services" app.
Then re-create the service with the correct data directory:
pg_ctl -register -D -D c:\customer\data -N postgresql-9.1
Another way of "debugging" startup errors in Windows, is to start Postgres from the command line (not through the service) because some errors during startup are not logged in the Postgres logfile but they are displayed on the command line. You can do that with e.g.:
pg_ctl start -D c:\customer\data`
If the bin directory is not in your PATH you need to specify the full path to it on the command line, e.g.: c:\Postgres9.1\bin\pg_ctl
I have a web application querying a Postgresql database (successfully) and I'm looking to move the data folder from location /var/lib/postgres/9.3/main to a customisable location.
Right now I'm prevented from even copying the folder due to permission errors, but I can't assign myself the permissions because that breaks the postgres server.
(I broke the server by running sudo chown <username> -R /var/lib/postgres/9.3/main - which worked as a command but stopped the postgres server from working)
I would simply create a new folder and change the location there, but I'll lose the current instance of my database if that was done.
How can I move the current folder to a new location, so that I can point to it in the .conf file? I need to explicitly move the folder, I can't create a new DB.
You can just copy or move the directory, including all subdirs and files
cp -rp or mv should be enough for this.
Postgres must not be running while you are messing with the files
The base of the data-drectory (PG_DATA) must be owned by postgres and have file mode 0700 . (when not: pg will refuse to start)
[the rest of the files must at least be readable/writeble by postgres]
the new location must also be known to the startup process (in /etc/init.d/ and (possibly) in the postgres.conf file within the data directory. (for the log file location)
I'm working on creating a Database Cluster (single database) in PostgreSQL 9.x working on a Linux system (CentOS - RedHat - Fedora). I've installed the correct PostgreSQL packages (server & client) however, I'm unable to create a database and get some type of initializing dependencies error: Bus Error / Exit Code 135. I've changed my user to "postgres" with "su postgres" and then tried to initialize the database with "initdb" (this may be the problem)
Installed: postgresql-libs-9.2.13-1.el7_1.x86_64
Installed: postgresql-9.2.13-1.el7_1.x86_64
Installed: postgresql-server-9.2.13-1.el7_1.x86_64
$ initdb -D /usr/local/pgsql/data
http://www.postgresql.org/docs/9.2/interactive/creating-cluster.html
Error:
$ initdb -D /usr/local/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.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
creating directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 32MB
creating configuration files ... ok
creating template1 database in /usr/local/pgsql/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... sh: line 1: 12616 Bus error (core dumped) "/usr/bin/postgres" --single -F -O -c search_path=pg_catalog -c exit_on_error=true template1 > /dev/null
child process exited with exit code 135
Any ideas?
After installing PostgreSQL (server and client tools) one needs to run the following commands as ROOT ("su"). The key step is to start "service postgresql initdb" and let it initialize your PostgreSQL database.
If you have any errors you need to remove the empty install "data" directories and read all log files carefully.
# service postgresql initdb
# systemctl enable postgresql
# systemctl start postgresql
After doing the above verify that postgres is in /var/lib/pgsql and a running process with "ps -ef | grep postgres" (its on port 5432)
If you run into any other problems you may need to create or modify a postgres user/password or clean a postgres data directory out.
If you installed from packages, you should use the package's provided methods for creating the DB. For the PDGD RPMs (from http://yum.postgresql.org/) that's documented in the README.rpm-dist:
/usr/pgsql-9.4/bin/postgresql94-setup initdb
However, the error you're getting really shouldn't happen. It suggests a hardware incompatibility or a low level issue like an incompatible C library. Perhaps you force-installed RPMs from a different OS or version?
Update:
Seems very likely to be a C library incompatibility. Perhaps an issue between RHEL and CentOS? Or version related? That's a fault in the dynamic linker. dl-lookup.c will be glibc/elf/dl-lookup.c and it seems to be crashing during symbol lookup. So there's something really wonky here, like a corrupt symbol hash table in the binary or an incompatibility between the binary and the dynamic linker used. Or a memory fault, disk fault, CPU cache issue, or other hardware error.
If rebooting makes it go away I'd be very suspicious of the hardware. If it doesn't, you might have something really wonky on the system like some 3rd party unpackaged installer overwriting the original C library / dynamic linker, that sort of weirdness.
Following my previous question I'm now trying to execute a batch file trough NSIS code in order to successfully setup the postgres installation after it is being unzipped. The batch file contains command for initializing the database but it fails because of permission restrictions. I am on a Win7 x64 PC. My user account is the administrator and I start the Setup.exe with Run as adminitrator option. This is the error I get:
C:\Program Files (x86)\Poker Assistant>cd "pgsql\bin"
C:\Program Files (x86)\Poker Assistant\pgsql\bin>initdb -U postgres -A
password
--pwfile "pwd.txt" -E utf8 -D "..\data" The files belonging to this database system will be owned by user "Mandarinite".
This user must also own the server process.
The database cluster will be initialized with locale
"Bulgarian_Bulgaria.1251". initdb: could not find suitable text search
configuration for locale "Bulgarian_ Bulgaria.1251" The default text
search configuration will be set to "simple".
Data page checksums are disabled.
creating directory ../data ... initdb: could not create directory
"../data": Permission denied
EDIT: After tinkering little more with the installer I got to the root of the problem. I cannot in any way execute the following command when the installation is in the Program Files folder:
initdb -U postgres -A password --pwfile "pwd.txt" -E utf8 -D "..\data"
I tried from .bat file. I tried from .cmd file. I tried manually from Command Prompt. I tried start as Administrator. All attempts resulted in the Permission denied error
EDIT2: I did not find any way to fix the problem so I made a workaround. Now I distribute the postgres with its data directory already initialized. Then I only need to create the service and start it.
I just realised what the issue here is.
If you run postgres as Administrator, it uses a special Windows API call to drop permissions (acquire a restricted token), so that it runs without full Administrator rights for security. See PostgreSQL utilities and restricted tokens on windows.
I suspect that what's happening here is that initdb isn't creating the target data directory and setting its permissions before doing that, so it drops permissions and then doesn't have the permissions to create the data directory.
To work around it, simply md ..\data to create the empty directory and then use icacls.exe to grant appropriate permissions before you try to initdb. Or, even better, store it in a more appropriate place like %PROGRAMDATA%\MyApp\pgdata or whatever; application data should not go in %PROGRAMFILES%.
I apologize for the long post. I have a Postgresql 9.3 server running on a Amazon linux AMI. I also have a compressed dump file from another server which I created using pg_dumpall. Now, I want to restore the data from this dump file in my Postgres. However, I want to load this data into a specific location (say /data).
I'm having a fresh installation of Postgres. So when I tried to do a:
sudo service postgresql93 start
I got an error message asking me to initialize the db. So I did a:
sudo service postgresql initdb
which created the required files in /var/lib/pgsql93/data. After that, I changed the 'data_directory' configuration in /var/lib/pgsql93/data/postgresql.conf and pointed it to /data (I had to do this as root user. I couldn't open the file as the default user).
Now when I try to do a
sudo service postgresql93 start
it fails to start, and when I check the /var/lib/pgsql93/pg_startup.log file, it says:
FATAL: "/data/postgresql" is not a valid data directory
DETAIL: File "/data/postgresql/PG_VERSION" is missing.
So I copied the files from the default (/var/lib/pgsql9.3/data) to /data, changed the permissions to 700 and owner to postgres.
However, when I try to start the service again, it still fails, and in the pgstartup.log, it only says:
LOG: redirecting log output to logging collector process
HINT: Future log output will appear in directory "pg_log".
And when I check the log in /data/pg_log, it says:
LOG: database system was shut down at 2014-12-30 21:31:18 UTC
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
What else could be the problem? I haven't restored the data yet. I just have the files which were created by the initdb command.
#BMW http://www.linuxquestions.org/questions/linux-server-73/change-postgresql-data-directory-649911/ is exactly what I was looking for. Thanks.