How to Install Postgresql v9.1 and JBoss AS v7.1.1 on Ubuntu 12.04 LTS - postgresql

There are really good sources that describe how to install Postgresql and JBoss on Ubuntu 12.04 LTS but information is distributed accross other pages.
However, it would be good to have a walktrough guide to easily install and configure these.

Preparing for installation
sudo apt-get install postgresql postgresql-contrib postgresql-common pgadmin3 openssh-server openssh-client
This command will install latest Postgresql, PgAdmin3, Postgresql-contrib and SSH server packages. SSH server is not necessarily required but it is good to manage the server remotely. So I've added it to the install list. [1]
Oracle Java JDK and JBoss AS installations are not automatic. So we should download them from their web sites. We'll use jdk-7u10-linux-i586.tar.gz (or later version) and jboss-as-7.1.1.Final.tar.gz
See http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html for JDK and http://www.jboss.org/jbossas/downloads/ for JBoss.
or try the commandline links below [2]. (The links might get invalid in the future, sorry for that...)
wget --no-cookies --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F" "http://download.oracle.com/otn-pub/java/jdk/7u10-b18/jdk-7u10-linux-i586.tar.gz"
wget "http://download.jboss.org/jbossas/7.1/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final.tar.gz"
Note that one might like to install OpenJDK which is available on apt-get repository and preferred by Ubuntu. However that is a preference and I'd like to use Oracle's JDK.
Optional: Adding extra locale support for Postgresql:
In my experience I needed Turkish locale support on Postgresql but it was not installed on Ubuntu by default. Here are sample commands to add Turkish collation support to Ubuntu, hence to Postgresql. [3]
sudo locale-gen tr_TR
sudo locale-gen tr_TR.UTF-8
Configuring Postgresql
We've already installed postgresql via apt-get. Now it would be good to make some changes to the config. [4]
By default Postgresql does not allow TCP connections. Edit postgresql.conf (my favorite editor is pico)
sudo pico /etc/postgresql/9.1/main/postgresql.conf
add
listen_addresses = '*' #Listens on all interfaces!!
or uncomment
listen_addresses = 'localhost' #More secure way to configure the server. Prefer this one if you won't connect to the server remotely
line.
If you selected to bind to all interfaces instead of localhost, then you'll need an extra configuration to allow remote connections. [5] Open up pg_hba.conf
sudo pico /etc/postgresql/9.1/main/pg_hba.conf
Add the line:
host all all 0.0.0.0/0 md5
Restart Postgresql to apply new config.
sudo /etc/init.d/postgresql restart
Now we'll set the password for default postgres user [6]. First fire up postgresql commandline.
sudo -u postgres psql
execute the following command. [7]
postgres=# ALTER USER postgres WITH ENCRYPTED PASSWORD '<your new password>';
Now you may connect to your server via PgAdmin3 or your favorite SQL Client or via command line...
Installing and Configuring Java and JBoss AS 7.1.1
I've selected /opt directory as our install directory. You are free to choose your own as long as you configure scripts accordingly. First extract JDK.
sudo tar -zxvf <Full Path to jdk-7u10-linux-i586.tar.gz> -C /opt
This will extract JDK to **/opt/jdk1.7.0_10* directory. Now we'll extract and configure JBoss AS. [8] [9]
First create a user for JBoss (jboss-as), it is a good habit to run your servers impersonating a user instead of directly executing them as root. This will tighten security.
sudo useradd -s /bin/sh jboss-as
Extract jboss-as-7.1.1.Final.tar.gz to /opt/jboss-as-7.1.1.Final
sudo tar -zxvf <Full Path to jboss-as-7.1.1.Final.tar.gz> -C /opt
I assume you'll run JBoss in standalone mode. Open up standalone.conf add the lines below.
JAVA_HOME="/opt/jdk1.7.0_10" #show your JAVA_HOME directory to JBoss
JAVA_OPTS="$JAVA_OPTS -Djboss.bind.address=0.0.0.0" #Bind to 0.0.0.0 so that remote clients can connect to your server.
Impersonate jboss-as user by executing
sudo -su jboss-as
First test the server by executing
cd /opt/jboss-as-7.1.1.Final
./standalone.sh
It should fire-up without problems. Use CTRL+C to shut down the server. You might connect to the server on your browser at port 8080.
http://<your server address>:8080
Now we'll create a management user for JBoss. It is required to use administration console running at port 9990.
export JAVA_HOME=/opt/jdk1.7.0_10/
./add-user.sh
Management User -> Select (a)
Realm (Management Realm) -> Accept the default and press enter
Username : -> Enter <your admin user name>
Password : -> Enter <your password>
Is this correct yes/no? -> Type 'yes' and press Enter
Added user '<your admin user name>' to file '/opt/jboss-as-7.1.1.Final/standalone/configuration/mgmt-users.properties'
Added user '<your admin user name>' to file '/opt/jboss-as-7.1.1.Final/domain/configuration/mgmt-users.properties'
Exit from impersonated jboss-as user.
exit
Now you may configure your server via its web interface at
http://<your server address>:9990
This address only accept your if you are at localhost Whenever you need to configure your server remotely, fire up the server with the following command.
sudo -u jboss-as ./standalone.sh -Djboss.bind.address.management=0.0.0.0
Again for security reasons do not bind to 0.0.0.0 if you don't need it.
Install JBoss as System Service
We'll prepare a server management script for init daemon (aka. init.d) [10]
cd /etc/init.d/
sudo pico jboss
Copy and paste the content below. Do not forget to modify JAVA_HOME, JBOSS_HOME directories and --chuid jboss-as (impersonates as jboss-as user when running the server) parameter accordingly.
#!/bin/sh
### BEGIN INIT INFO
# Provides: jboss
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/Stop JBoss AS v7.1.1 Final
### END INIT INFO
#
#source some script files in order to set and export environmental variables
#as well as add the appropriate executables to $PATH
export JAVA_HOME=/opt/jdk1.7.0_10
export PATH=$JAVA_HOME/bin:$PATH
export JBOSS_HOME=/opt/jboss-as-7.1.1.Final
export PATH=$JBOSS_HOME/bin:$PATH
case "$1" in
start)
echo "Starting JBoss AS 7.1.1 Final"
start-stop-daemon --start --quiet --background --chuid jboss-as --exec ${JBOSS_HOME}/bin/standalone.sh
;;
stop)
echo "Stopping JBoss AS 7.1.1 Final"
start-stop-daemon --start --quiet --background --chuid jboss-as --exec ${JBOSS_HOME}/bin/jboss-cli.sh -- --connect command=:shutdown
;;
*)
echo "Usage: /etc/init.d/jboss {start|stop}"
exit 1
;;
esac
exit 0
Set the script as executable and update rc.d
sudo chmod +x jboss
sudo update-rc.d jboss defaults
Now JBoss will start with your server. You might use the commands below to start and stop the server
sudo service jboss start
sudo service jboss stop

Related

How can I install pgAgent for PostgreSQL 9.5 on Windows?

Everything I see about pgAgent says that it can be installed using the StackBuilder wizard that runs after installing PostgreSQL. But the StackBuilder wizards I have do not include pgAgent. How can I get pgAgent?
A screenshot of my StackBuilder dialog box showing the lack of pgAgent can be found here: https://imgur.com/PTopsAA
I think it can't be possible, 9.5 is dead (EOL). but the binaries still can be downloaded from EDB ( https://www.enterprisedb.com/downloads/postgres-postgresql-downloads )
NOTE: pgAgent is available in Debian/Ubuntu (DEB) and Redhat/Fedora
(RPM) packages for Linux users, as well as source code
In the official doc says how: https://www.pgadmin.org/docs/pgadmin4/latest/pgagent_install.html#service-installation-on-windows
Service installation on Windows
pgAgent can install itself as a service on Windows systems. The command line options available are similar to those on Unix systems, but include an additional parameter to tell the service what to do:
Usage:
pgAgent REMOVE <serviceName>
pgAgent INSTALL <serviceName> [options] <connect-string>
pgAgent DEBUG [options] <connect-string>
options:
-u <user or DOMAIN\user>
-p <password>
-d <displayname>
-t <poll time interval in seconds (default 10)>
-r <retry period after connection abort in seconds (>=10, default 30)>
-l <logging verbosity (ERROR=0, WARNING=1, DEBUG=2, default 0)>
The service may be quite simply installed from the command line as follows (adjust the path as required):
"C:\Program Files\pgAgent\bin\pgAgent" INSTALL pgAgent -u postgres -p secret hostaddr=127.0.0.1 dbname=postgres user=postgres
You can then start the service at the command line using net start pgAgent, or from the Services control panel applet. Any logging output or errors will be reported in the Application event log. The DEBUG mode may be used to run pgAgent from a command prompt. When run this way, log messages will output to the command window.

how to install Odoo 9 on ubuntu?

I have pre installed postgres , postgres-9.3 and pgadmin on port 5432 and 5433 .
uninstall them then trying to install odoo 9 using http://openies.com/blog/install-openerp-odoo-9-on-ubuntu-server-14-04-lts/
this tutorial .
but when i ttrying to execute command
createuser --createdb --username postgres --no-createrole --no-superuser --pwprompt odoo
then it gives following error :
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
"/var/run/postgresql/.s.PGSQL.5432"?
sudo netstat -nltp | grep 5432 is not showing any result .
pg_hba.conf
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
1. Introduction
In this tutorial I will learn you how to install Odoo 9 on Ubuntu 14.04. The script that you will use is based on the code from André Schenkels but has been updated and improved.
2. Downloading the script
The first step is to download my script from GitHub and to add the code in a new .sh file on your Ubuntu machine, wherever you’d like this.
For example right under /home. Open up an Ubuntu terminal and cd to the directory where you’d like to keep the script and then create the file:
sudo wget https://raw.githubusercontent.com/Yenthe666/InstallScript/9.0/odoo_install.sh
If you’re curious about how the whole code looks and works you can find it on my Github account.
Now open up the file and edit the parameters to your liking:
sudo nano odoo_install.sh
There are some things you can configure/change to your likings at the top of the script. You can choose if you wish to install Wkhtmltopdf or not, which version you’d like, where the location is and most importantly what the master admin password is. Tip: always modify this for every Odoo you install!
3. Making the Odoo installation file executable
The next step is to make this file executable. After you’ve made it executable you can execute it and everything will be installed automatically.
do this with the following command:
sudo chmod +x odoo_install.sh
4.Running the script
Now that the code is in your file and the file is executable you simply have to execute it with the following command:
./odoo_install.sh
You will see that the script automatically starts updates, downloads required packages, creates the user, downloads the code from Github, …
Give the script a few minutes to configure and install everything and eventually you will see something like this:
You now have a fully functional Odoo V9 on your system! Congratulations.
Odoo V9
5. Extra information
In the script you saw there was an option to change the Odoo port (OE_PORT). When you’d change this port number to 8070 in the install script it would be applied to /etc/your-config-file.conf and this would give you the ability to change the default port.
To apply these changes you should do the following:
The -c will change the configuration and memorize what you’ve changed under /etc/your-config-file.conf. Because my port was set to 8070 this is telling the Odoo that it should run on port 8070. When you would now open up your browser and navigate to http://localhost:8070/ you will see it is running there:
Odoo V9 alternative port
This issue comes form installing the postgres package with out a version number. Although postgres will be installed and it will be the correct version the script to setup the cluster will not be run correctly. It's a packaging issue. If your comfortable with Postgres there is a script you can run to crete this cluster and get postgres running however if your like me then you do it the easy way. First purdge the old postgres install. The issue currently lies with 9.1 so I will assume that's what you have installed
sudo apt-get remove --purge postgresql-9.1
Now simply reinstall
sudo apt-get install postgresql-9.1
Note the package name with the version number. HTH.
I have installed odoo using http://openies.com/blog/install-openerp-odoo-9-on-ubuntu-server-14-04-lts/ got no issue with the fresh ubuntu 14.04 LTS.
But, you need to check that there is no postmaster.pid in your postgres directory, probably /usr/local/var/postgres/
Remove this and start server using
rm /usr/local/var/postgres/postmaster.pid
It should work.
Check this to install odoo 10 in ubuntu 16.04 LTS
Bitnami ODOO, easy to install in your Machine.
Download from Here
It is compatible with preinstall postgresql.
As mentioned before you can use one simple script to install Odoo of any version (9, 10, 11).
Follow the steps:
Log in to your system and work as an superuser: sudo su
Update the system: apt-get update
Download the script. You can change to the version of your choice:
wget https://raw.githubusercontent.com/Yenthe666/InstallScript/11.0/odoo_install.sh
Run the script: ./odoo_install.sh
Now you can access Odoo at http://serverIP:8069
If you are running it locally that would be 127.0.0.1:8069
The next steps would be to configure the Apache/Nginx or another server to point a domain to the Odoo instance. Also, remember to set the proper access rules on your server (for example on Amazon that would be by opening the port 80 and 8069 in the security rules). It is also wise to change the default password in Odoo config from admin to something more secure.
If you used the script without editing your Odoo config file would be installed in /etc/odoo-serfer.config. Use nano, vi or another editor to change the default settings.

Concurrent users at multi location using Firebird

How can I use firebird to connect to my database (host) from the other computer at different location 50km away?
Is there an online method? How to do it?
I use SSH tunnels. On Ubuntu 14.04 with Upstart and autossh installed,
you#your-local-server:/etc/init$ cat autossh-other-server.conf
description "autossh other-server service"
version "1.0"
author "Your Name"
start on runlevel [2345]
stop on runlevel [016]
script
exec start-stop-daemon --start -c some-user-with-ssh-keys --exec /usr/bin/autossh -- -N -p 2022 other-server.your-domain.com -L 0.0.0.0:3052:localhost:3050
end script
Note that I already had a user setup with ssh keys for no-password ssh connections to the remote host. Your software on this side can connect to Firebird on port 3052.

How to upgrade PostgreSQL from version 9.6 to version 10.1 without losing data? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I'm using the PostgreSQL database for my Ruby on Rails application (on Mac OS X 10.9).
Are there any detailed instructions on how to upgrade PostgreSQL database?
I'm afraid I will destroy the data in the database or mess it up.
Assuming you've used home-brew to install and upgrade Postgres, you can perform the following steps.
Stop current Postgres server:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Initialize a new 10.1 database:
initdb /usr/local/var/postgres10.1 -E utf8
run pg_upgrade (note: change bin version if you're upgrading from something other than below):
pg_upgrade -v \
-d /usr/local/var/postgres \
-D /usr/local/var/postgres10.1 \
-b /usr/local/Cellar/postgresql/9.6.5/bin/ \
-B /usr/local/Cellar/postgresql/10.1/bin/
-v to enable verbose internal logging
-d the old database cluster configuration directory
-D the new database cluster configuration directory
-b the old PostgreSQL executable directory
-B the new PostgreSQL executable directory
Move new data into place:
cd /usr/local/var
mv postgres postgres9.6
mv postgres10.1 postgres
Restart Postgres:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Check /usr/local/var/postgres/server.log for details and to make sure the new server started properly.
Finally, re-install the rails pg gem
gem uninstall pg
gem install pg
I suggest you take some time to read the PostgreSQL documentation to understand exactly what you're doing in the above steps to minimize frustrations.
Despite all answers above, here goes my 5 cents.
It works on any OS and from any-to-any postgres version.
Stop any running postgres instance;
Install the new version and start it; Check if you can connect to the new version as well;
Change old version's postgresql.conf -> port from 5432 to 5433;
Start the old version postgres instance;
Open a terminal and cd to the new version bin folder;
Run pg_dumpall -p 5433 -U <username> | psql -p 5432 -U <username>
Stop old postgres running instance;
Here is the solution for Ubuntu users
First we have to stop postgresql
sudo /etc/init.d/postgresql stop
Create a new file called /etc/apt/sources.list.d/pgdg.list and add below line
deb http://apt.postgresql.org/pub/repos/apt/ utopic-pgdg main
Follow below commands
wget -q -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.4
sudo pg_dropcluster --stop 9.4 main
sudo /etc/init.d/postgresql start
Now we have everything, just need to upgrade it as below
sudo pg_upgradecluster 9.3 main
sudo pg_dropcluster 9.3 main
That's it. Mostly upgraded cluster will run on port number 5433. Check it with below command
sudo pg_lsclusters
If you are using homebrew and homebrew services, you can probably just do:
brew services stop postgresql
brew upgrade postgresql
brew postgresql-upgrade-database
brew services start postgresql
I think this might not work completely if you are using advanced postgres features, but it worked perfectly for me.
Update: This process is the same for upgrading 9.5 through at least 11.5; simply modify the commands to reflect versions 9.6 and 10, where 9.6 is the old version and 10 is the new version. Be sure to adjust the "old" and "new" directories accordingly, too.
I just upgraded PostgreSQL 9.5 to 9.6 on Ubuntu and thought I'd share my findings, as there are a couple of OS/package-specific nuances of which to be aware.
(I didn't want to have to dump and restore data manually, so several of the other answers here were not viable.)
In short, the process consists of installing the new version of PostgreSQL alongside the old version (e.g., 9.5 and 9.6), and then running the pg_upgrade binary, which is explained in (some) detail at https://www.postgresql.org/docs/9.6/static/pgupgrade.html .
The only "tricky" aspect of pg_upgrade is that failure to pass the correct value for an argument, or failure to be logged-in as the correct user or cd to the correct location before executing a command, may lead to cryptic error messages.
On Ubuntu (and probably Debian), provided you are using the "official" repo, deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main, and provided you haven't changed the default filesystem paths or runtime options, the following procedure should do the job.
Install the new version (note that we specify the 9.6, explicitly):
sudo apt install postgresql-9.6
Once installation succeeds, both versions will be running side-by-side, but on different ports. The installation output mentions this, at the bottom, but it's easy to overlook:
Creating new cluster 9.6/main ...
config /etc/postgresql/9.6/main
data /var/lib/postgresql/9.6/main
locale en_US.UTF-8
socket /var/run/postgresql
port 5433
Stop both server instances (this will stop both at the same time):
sudo systemctl stop postgresql
Switch to the dedicated PostgreSQL system user:
su postgres
Move into his home directory (failure to do this will cause errors):
cd ~
pg_upgrade requires the following inputs (pg_upgrade --help tells us this):
When you run pg_upgrade, you must provide the following information:
the data directory for the old cluster (-d DATADIR)
the data directory for the new cluster (-D DATADIR)
the "bin" directory for the old version (-b BINDIR)
the "bin" directory for the new version (-B BINDIR)
These inputs may be specified with "long names", to make them easier to visualize:
-b, --old-bindir=BINDIR old cluster executable directory
-B, --new-bindir=BINDIR new cluster executable directory
-d, --old-datadir=DATADIR old cluster data directory
-D, --new-datadir=DATADIR new cluster data directory
We must also pass the --new-options switch, because failure to do so results in the following:
connection to database failed: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/lib/postgresql/.s.PGSQL.50432"?
This occurs because the default configuration options are applied in the absence of this switch, which results in incorrect connection options being used, hence the socket error.
Execute the pg_upgrade command from the new PostgreSQL version:
/usr/lib/postgresql/9.6/bin/pg_upgrade --old-bindir=/usr/lib/postgresql/9.5/bin --new-bindir=/usr/lib/postgresql/9.6/bin --old-datadir=/var/lib/postgresql/9.5/main --new-datadir=/var/lib/postgresql/9.6/main --old-options=-cconfig_file=/etc/postgresql/9.5/main/postgresql.conf --new-options=-cconfig_file=/etc/postgresql/9.6/main/postgresql.conf
Logout of the dedicated system user account:
exit
The upgrade is now complete, but, the new instance will bind to port 5433 (the standard default is 5432), so keep this in mind if attempting to test the new instance before "cutting-over" to it.
Start the server as normal (again, this will start both the old and new instances):
systemctl start postgresql
If you want to make the new version the default, you will need to edit the effective configuration file, e.g., /etc/postgresql/9.6/main/postgresql.conf, and ensure that the port is defined as such:
port = 5432
If you do this, either change the old version's port number to 5433 at the same time (before starting the services), or, simply remove the old version (this will not remove your actual database content; you would need to use apt --purge remove postgresql-9.5 for that to happen):
apt remove postgresql-9.5
The above command will stop all instances, so you'll need to start the new instance one last time with:
systemctl start postgresql
As a final point of note, don't forget to consider pg_upgrade's good advice:
Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade so,
once you start the new server, consider running:
./analyze_new_cluster.sh
Running this script will delete the old cluster's data files:
./delete_old_cluster.sh
The user manual covers this topic in depth. You can:
pg_upgrade in-place; or
pg_dump and pg_restore.
If in doubt, do it with dumps. Don't delete the old data directory, just keep it in case something goes wrong / you make a mistake; that way you can just go back to your unchanged 9.3 install.
For details, see the manual.
If you're stuck, post a detailed question explaining how you're stuck, where, and what you tried first. It depends a bit on how you installed PostgreSQL too, as there are several different "distributions" of PostgreSQL for OS X (unfortunately). So you'd need to provide that info.
Standing on the shoulders of the other poor creatures trodding through this muck, I was able to follow these steps to get back up and running after an upgrade to Yosemite:
Assuming you've used home-brew to install and upgrade Postgres, you can perform the following steps.
Stop current Postgres server:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Initialize a new 9.4 database:
initdb /usr/local/var/postgres9.4 -E utf8
Install postgres 9.3 (as it was no longer present on my machine):
brew install homebrew/versions/postgresql93
Add directories removed during Yosemite upgrade:
mkdir -p /usr/local/var/postgres/{pg_tblspc,pg_twophase,pg_stat_tmp}/touch /usr/local/var/postgres/{pg_tblspc,pg_twophase,pg_stat_tmp}/.keep
run pg_upgrade:
pg_upgrade -v -d /usr/local/var/postgres -D /usr/local/var/postgres9.4 -b /usr/local/Cellar/postgresql93/9.3.5/bin/ -B /usr/local/Cellar/postgresql/9.4.0/bin/
Move new data into place:
cd /usr/local/var
mv postgres postgres9.3
mv postgres9.4 postgres
Restart Postgres:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Check /usr/local/var/postgres/server.log for details and to make sure the new server started properly.
Finally, re-install related libraries?
pip install --upgrade psycopg2
gem uninstall pg
gem install pg
Looks like the solution has been baked into Homebrew now:
$ brew info postgresql
...
==> Caveats
To migrate existing data from a previous major version of PostgreSQL run:
brew postgresql-upgrade-database
....
On Windows I kept facing different errors messages when trying to use pg_upgrade.
Saved a lot of time for me to just:
Backup DB
Uninstall all copies of PostgreSQL
Install 9.5
Restore DB
This did it for me.
https://gist.github.com/dideler/60c9ce184198666e5ab4
Short and to the point. I honestly don't aim to understand the guts of PostgreSQL, I want to get stuff done.
My solution for upgrading from Postgresql 11 to Postgresql 12 on Windows 10 is the following.
As a first remark you will need to be able stop and start the Postgresql service. You can do this by the following commands in Powershell.
Start:
pg_ctl start -D “d:\postgresql\11\data”
Stop:
pg_ctl stop -D “d:\postgresql\11\data”
Status:
pg_ctl status -D “d:\postgresql\11\data”
It would be wise to make a backup before doing the upgrade. The Postgresql 11 instance must be running. Then to copy the globals do
pg_dumpall -U postgres -g -f d:\bakup\postgresql\11\globals.sql
and then for each database
pg_dump -U postgres -Fc <database> > d:\backup\postgresql\11\<database>.fc
or
pg_dump -U postgres -Fc -d <database> -f d:\backup\postgresql\11\<database>.fc
If not already done install Postgresql 12 (as Postgresql 11 is also installed this will be on port 5433)
Then to do the upgrade as follows:
1) Stop Postgresql 11 service (see above)
2) Edit the postgresql.conf file in d:\postgresql\12\data and change port = 5433 to port = 5432
3) Edit the windows user environment path (windows start then type env) to point to Postgresql 12 instead of Postresql 11
4) Run upgrade by entering the following command.
pg_upgrade `
-b “c:\program files\postgresql\11\bin” `
-B “c:\program files\postgresql\12\bin” `
-d “d:\postgresql\11\data” `
-D “d:\postgresql\12\data” --username=postgres
(In powershell use backtick (or backquote) ` to continue the command on the next line)
5) and finally start the new Postgresql 12 service
pg_ctl start -D “d:\postgresql\12\data”
My solution was to do a combination of these two resources:
https://gist.github.com/tamoyal/2ea1fcdf99c819b4e07d
and
http://www.gab.lc/articles/migration_postgresql_9-3_to_9-4
The second one helped more then the first one. Also to not, don't follow the steps as is as some are not necessary.
Also, if you are not being able to backup the data via postgres console, you can use alternative approach, and backup it with pgAdmin 3 or some other program, like I did in my case.
Also, the link: https://help.ubuntu.com/stable/serverguide/postgresql.html
Helped to set the encrypted password and set md5 for authenticating the postgres user.
After all is done, to check the postgres server version run in terminal:
sudo -u postgres psql postgres
After entering the password run in postgres terminal:
SHOW SERVER_VERSION;
It will output something like:
server_version
----------------
9.4.5
For setting and starting postgres I have used command:
> sudo bash # root
> su postgres # postgres
> /etc/init.d/postgresql start
> /etc/init.d/postgresql stop
And then for restoring database from a file:
> psql -f /home/ubuntu_username/Backup_93.sql postgres
Or if doesn't work try with this one:
> pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d name_of_database ~/your_file.dump
And if you are using Rails do a bundle exec rake db:migrate after pulling the code :)
For Mac via homebrew:
brew tap petere/postgresql,
brew install <formula> (eg: brew install petere/postgresql/postgresql-9.6)
Remove old Postgres:
brew unlink postgresql
brew link -f postgresql-9.6
If any error happen, don't forget to read and follow brew instruction in each step.
Check this out for more: https://github.com/petere/homebrew-postgresql
On Windows 10 since I had npm, I installed rimraf package. npm install rimraf -g
Backup all your databases one by one using command pg_dump -U $username --format=c --file=$mydatabase.sqlc $dbname
Then Installed Latest PostgreSQL Version i.e. 11.2 which prompted me to use port 5433 this time.
Followed by Uninstall of older versions of PostgreSQL mine was 10. Note the uninstaller may give a warning of not deleting folder C:\PostgreSQL\10\data. That's why we have the next step using rimraf to permanently delete the folder and it's sub-folders.
change into PostgreSQL install directory and ran the command rimraf 10. 10 is a directory name. Note use your older version of PostgreSQL i.e. 9.5 or something.
Now add C:\PostgreSQL\pg11\bin, C:\PostgreSQL\pg11\lib into the Windows environmental variables. Note my new installed version is 11 thus why I am using pg11.
Navigate to C:\PostgreSQL\data\pg11 then open postgresql.conf edit port = 5433 to port = 5432
That's it. Open cmd and type psql -U postgres
You can now restore all your backed databases one by one using the command pg_restore -U $username --dbname=$databasename $filename
I think this is best link for your solution to update postgres to 9.6
https://sandymadaan.wordpress.com/2017/02/21/upgrade-postgresql9-3-9-6-in-ubuntu-retaining-the-databases/

I have installed PostgreSQL via MacPorts, but cannot access it

As I said in title, I've installed PostgreSQL usind MacPorts, but cannot access it.
The installation process was
$ sudo port install postgresql83-server
$ sudo mkdir -p /opt/local/var/db/postgresql83/webcraft
$ sudo chown postgres:postgres /opt/local/var/db/postgresql83/webcraft
$ sudo su postgres -c '/opt/local/lib/postgresql83/bin/initdb -D /opt/local/var/db/postgresql83/webcraft'
$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql83-server.plist
My PATH is
/opt/local/lib/postgresql83/bin:/opt/local/lib/mysql5/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
I try to connect the server using psql client
$ psql
psql: 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"?
Here is some info
$ ps ax | grep postgres | grep -v grep
52 ?? Ss 0:00.00 /opt/local/bin/daemondo --label=postgresql83-server --start-cmd /opt/local/etc/LaunchDaemons/org.macports.postgresql83-server/postgresql83-server.wrapper start ; --stop-cmd /opt/local/etc/LaunchDaemons/org.macports.postgresql83-server/postgresql83-server.wrapper stop ; --restart-cmd /opt/local/etc/LaunchDaemons/org.macports.postgresql83-server/postgresql83-server.wrapper restart ; --pid=none
Did you try running:
which psql
I imagine psql is still referencing /usr/bin/psql, and the macports version of psql is suffixed with the version number, in your case psql83. You can alias psql to psql83 as a simple workaround. Better would be to change the default:
sudo port select --set postgresql postgresql83
That will do the proper routing.
There is a very easy solution to this, but it's not well documented in my opinion:
MacPorts encourages installing their *_select ports to manage potentially multiple versions of software (say you want Postgres93 and Postgres94 at the same time). It's a great feature, but it adds an extra step that is for some reason rarely mentioned in the docs:
$ sudo port install postgresql94-server
Many failed attempts at starting the server later..
$ sudo port install postgresql_select
$ sudo port select postgresql
Available versions for postgresql:
none (active)
postgresql94
Well that can't be good!
$ sudo port select postgresql postgresql94
$ sudo port load postgresql94-server
You're kidding me. Now it's running?
Simply installing Postgres doesn't fully setup symlinks to make it easily runnable. Installing postrgresql_select gives MacPorts the information it needs to do that via port select. Once you've selected the active version of your choice, starting the Posgres server via luanchctl is as easy as port load postgresqlXX-server.
I know this is a very late answer and doesn't answer your full question, but launchctl will show different results depending on if you are superuser or not.
Try doing:
sudo launchctl list | grep postgres
I had exactly the same problem on my MacBook Pro. I could resolve the problem after I rode this blog post here and all the comments:
http://benscheirman.com/2010/06/installing-postgresql-for-rails-on-mac-os-x
The Problem is that postgres is not really running. I recognized this after I did a port scan to my own machine and realized that nothing is running on Port 5432.
I created a small script "start_pg_server.sh":
#!/bin/sh
sudo su postgres -c 'pg_ctl start -D /opt/local/var/db/postgresql83/defaultdb/'
after executing this script the server was running and I could connect me with pgAdmin. I was also able to run my ruby stuff with rake db:create and rake db:migrate.
After I restored using Timemachine I had the same problem.
The reason was that the permissions were mangled and postgres could not write the pid file.
Running this solved it for me:
sudo chown -R postgres:postgres /opt/local/var/db/postgresql91/
sudo port unload postgresql91-server
sudo port load postgresql91-server
Did you by any chance create your postgres user with a shell of /usr/bin/false? If so, the startup script won't work because it uses su which passes commands you send it through the shell.
If you did set it to /usr/bin/false, try changing it to /bin/bash and that might fix things.