Travis OS X test Postgres - macos

How can I set Postgres in Travis CI OS X build?
I can't start and I don't know how to set these:
--dbaddress localhost --dbport 5432 --dbname testDb --dbusername postgres

With the Travis CI OS X instances the environment is similar to a typical Homebrew installation.
Here is the Travis CI OS X environment you can configure.
The database services that are available:
postgis version 2.1.3, postgresql version 9.3.5
Unlike Linux, the service configuration is not currently available in OSX. You start a database service using the install script and making use of the Postgresql tools directly.
An example .travis.yml looks like this:
addons:
postgresql: "9.4"
language:
- objective-c
os:
- osx
sudo:
- false
install:
- export PG_DATA=$(brew --prefix)/var/postgres
- pg_ctl -w start -l postgres.log --pgdata ${PG_DATA}
- createuser -s postgres
- psql -c 'create database testDb;' -U postgres
- cat postgres.log
So what does it do?
“add ons” is selecting your specific postgresql version over the default
“sudo” commands cannot be executed in Travis CI
“install” contains the commands we need to run and others you want to add
The pg_ctl command requires a data directory, “PG_DATA” contains a path to the local home-brew installation and your directory to store database files.
pg_ctl will start the existing service and wait(-w) to be connected.
A unix user/role "postgres" must be created and is used in the final creation script for your database “testDb”.
Finally, the postgres.log is sent to Travis CI log.
Hopefully, that gives you an idea of where to start.

Additional information to griffio's answer:
In the meantime Travis is running PostgreSQL 9.5 (even with addon postgresql: "9.4") and I got the following log output when starting:
FATAL: database files are incompatible with server
DETAIL: The data directory was initialized by PostgreSQL version 9.4, which is not compatible with this version 9.5.4.
It's working after creating a new cluster first:
install:
- export PG_DATA=$(brew --prefix)/var/postgres
- rm -rf $PG_DATA
- initdb $PG_DATA -E utf8
- pg_ctl -w start -l postgres.log --pgdata ${PG_DATA}
- createuser -s postgres
- psql -c 'create database testDb;' -U postgres

Related

How to use oracle11g on Docker?

just now, i reinstall OSX on my macbook. Then i install Docker Desktop.
Because i want to use oracle database. But i encountered this logs.
Database is not installed. Installing...
Installation files not found. Unzip installation files into mounted(/install) folder
at first, i install SQL Developer. and in Terminal, i install jaspeen/oracle-11g by docker.
then, i run docker image.
$ docker run -d -p 59160:22 -p 59161:1521 jaspeen/oracle-11g
then, i typed
$ docker ps -l
but container's status is 'Exited (1) 16 seconds ago'
12750f964708 jaspeen/oracle-11g "/assets/entrypoint.…" 17 seconds ago Exited (1) 16 seconds ago busy_dewdney
if i have to install oracle database in ORACLE homepage?
I had the same issue and solved it by:
downloading "Linux x86-64" from https://www.oracle.com/database/technologies/oracle-database-software-downloads.htm
unzip both files into the same folder. In the end, you will have one single "database" folder where you had just unzip both files.
(just for the sake of the example you gave) move this folder (the "database" folder) into the "install_folder" folder
execute docker run --privileged --name oracle11g -p 1521:1521 -v path/to/your/install_folder:/install jaspeen/oracle-11g . The idea here is that the value you set for the "path/to/your/install_folder" to be the location of the folder that contains the "database" folder. In your case is it the "install_folder" folder. That -v flag is actually mounting your "install_folder" into docker container at "/install" location.
It will take a while until the process ends. It should first output the following:
Database is not installed. Installing...
Installing Oracle Database 11g
Starting Oracle Universal Installer...
Checking Temp space: must be greater than 120 MB. Actual 50321 MB Passed
Checking swap space: must be greater than 150 MB. Actual 856 MB Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2020-03-30_08-00-03PM. Please wait ...
When you can connect to it with credentials below, then it is up&running:
username/password: SYS/oracle
SID: orcl
Note: I had tried more than one release from Oracle's download site until I found the lucky one. For example, in one situation the console just exited without any reason. When I typed docker ps, it showed that container exited with status 255 (which I did not find helpful).
I also found inspiration from here: https://programmer.group/install-oracle-11g-using-docker.html
Download database installation files from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index-092322.html and unpack them to install_folder. Run container and it will install oracle and create database:
docker run --privileged --name oracle11g -p 1521:1521 -v :/install jaspeen/oracle-11g

Docker Postgres with windows share

I migrated from Linux to Windows and tried to setup a postgres container with a mounted directory (copied from my Linux install) containing the database.
This does not work.
Windows mounts are always owned by root
Postgres does not run under root
How to get this unholy combination to work?
You don't provide much details so it is difficult to tell what actually went wrong. However there is a known issue with Postgres setup on Windows Docker using a windows mount for database data files. In that case, running docker logs will show something along the following lines
waiting for server to start....FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
HINT: The server must be started by the user that owns the data directory.
stopped waiting
pg_ctl: could not start server
Unfortunately there is no way to overcome this issue so you cannot use Windows mount, see Postgres Data has wrong ownership. You may use docker volumes in order to make database data indipendent from docker postgres container, using the following commands
docker create -v /var/lib/postgresql/data --name PostgresData alpine
docker run -p 5432:5432 --name yourPostgres -e POSTGRES_PASSWORD=yourPassword -d --volumes-from PostgresData postgres
You may find a more thoroughful explanation at Setup Postgresql on Windows with Docker

Error with starting PostgreSQL database on macOS

I am running the latest version of macOS Sierra and I installed PostgreSQL via brew. Then I ran the command:
pg_ctl -D /Users/tmo/PSQL-data -l logfile start
but received for output:
waiting for server to start..../bin/sh: logfile: Permission denied
stopped waiting
pg_ctl: could not start server
Examine the log output.
EDIT: After restarting my operating system and rerunning the command... I'm now receiving a slightly modified output... but the modification is significant.
waiting for server to start.... stopped waiting
pg_ctl: could not start server
Examine the log output.
Where is the "log output" stored?
How do I make this command work?
The problem could be one of two things, that I can see:
A typo in your database path:
/Users/tmo/PSQL-data --> /Users/tmp/PSQL-data
If the above was just a transcription error, I would guess that your postgres user doesn't have write access to the directory where you are setting the logfile. The argument following the -l switch tells PG where to save the logfile. When you don't provide the -l switch with a path, but just a filename, it will use the same dir you use to specify the database cluster (with the -D flag). So in this case, PG is trying to write to /Users/tmp/PSQL-data/logfile, and getting a permission error.
To fix this, I would try:
If the directory /Users/tmp/PSQL-data/ doesn't exist:
sudo mkdir /Users/tmp/PSQL-data
Then create the logfile manually:
sudo touch /Users/tmp/PSQL-data/logfile
Then make the postgres user own the file (I'm assuming user is postgres here)
sudo chown postgres /Users/tmp/PSQL-data/logfile
Try again, and hopefully you can launch the server.
Caveat: I'm not a macOS user, so I'm not sure how the /tmp folder behaves. If it is periodically cleared, you may want to specify a different logfile location, so that you don't need to create and chown the file each time you need to launch the cluster.

Centos 6.6 postgresql error: cannot execute binary file

I am running this on centos 6.6
PSQL='/usr/bin/psql'
su - postgres "$PSQL" template1 -f 'sql.sql'
But starting psql always fails to start
Starting postgresql-9.4 service: [FAILED]
and then I get this error
/usr/bin/psql: /usr/bin/psql: cannot execute binary file
Thank you for all the help.
Try this:
PSQL='/usr/bin/psql'
su - postgres -c "$PSQL template1 -f 'sql.sql'"

How to resolve this PostgreSQL error on OS 10.6 (Snow Leopard)

I followed the instructions for setting up postgresql from this site
All seems to go fine until I try:
createuser --superuser myname -U
postgres
I get the following exception:
createuser: could not connect to
database postgres: could not connect
to server: No such file or directory
Is the server running locally and
accepting connections on Unix domain
socket "/tmp/.s.PGSQL.5432"?
For the life of me I can't figure out how to resolve this. Any ideas???
I had to remove the existing postgres user before doing the install.
Perhaps you moved your postgres data directory after you installed postgres using macports
Find where your launchctl startup script is located.
ps -ef | grep postgres
Outputs
0 54 1 0 0:00.01 ?? 0:00.01 /opt/local/bin/daemondo --label=postgresql84-server --start-cmd /opt/local/etc/LaunchDaemons/org.macports.postgresql84-server/postgresql84-server.wrapper start ; --stop-cmd /opt/local/etc/LaunchDaemons/org.macports.postgresql84-server/postgresql84-server.wrapper stop ; --restart-cmd /opt/local/etc/LaunchDaemons/org.macports.postgresql84-server/postgresql84-server.wrapper restart ; --pid=none
So I edit
sudo vim /opt/local/etc/LaunchDaemons/org.macports.postgresql84-server/postgresql84-server.wrapper
And find the line
Start() {
su postgres -c "${PGCTL} -D ${POSTGRESQL84DATA:=/opt/local/var/db/postgresql84/wrong_place} start -l /opt/local/var/log/postgresql84/postgres.log"
}
Ahh.. my data directory is in the wrong place. I fix it by changing
/opt/local/var/db/postgresql84/wrong_place
to
/opt/local/var/db/postgresql84/right_place
for both the start and stop command.
Did you install the postgresql84-server port? If so, did you start the server:
$ sudo port load postgresql84-server
If you did both of those, I've noticed that sometimes the MacPorts daemon handler (daemondo) doesn't start handling requests for PostgreSQL until you restart your machine. (This only happens the first time it is started; subsequent attempts should work fine.)

Resources