19 September 2018

Installing PostgreSQL 9.6 on macOS 10.13.6 via MacPorts for Development Purposes

After finally receiving a new MacBook Pro with 2.9 Ghz, 6-core i9 processor and 32gb of memory, I am reinstalling all of my development tools. Not only is the big increase in resources really useful from the development point of view, but the computer is lighter and thinner as well. That being said, there are still things I do not like, such as the keyboard, the touchbar (I miss the tactile feedback from the escape key which, as a Vim user, I use constantly) and some other minor things. For my own purposes, I usually document the steps to make it easier in the future. But I also figured it might help other folks out there to achieve the same ends.


Having documented this procedure once or twice before, I'm going to keep this brief.



$ $ sudo port install postgresql96-server
---> Computing dependencies for postgresql96-server
The following dependencies will be installed:
libxml2
libxslt
postgresql96
postgresql_select
Continue? [Y/n]:
---> Fetching archive for libxml2
---> Attempting to fetch libxml2-2.9.7_0.darwin_17.x86_64.tbz2 from https://packages.macports.org/libxml2
---> Attempting to fetch libxml2-2.9.7_0.darwin_17.x86_64.tbz2.rmd160 from https://packages.macports.org/libxml2
---> Installing libxml2 @2.9.7_0
---> Activating libxml2 @2.9.7_0
---> Cleaning libxml2
---> Fetching archive for libxslt
---> Attempting to fetch libxslt-1.1.32_0.darwin_17.x86_64.tbz2 from https://packages.macports.org/libxslt
---> Attempting to fetch libxslt-1.1.32_0.darwin_17.x86_64.tbz2.rmd160 from https://packages.macports.org/libxslt
---> Installing libxslt @1.1.32_0
---> Activating libxslt @1.1.32_0
---> Cleaning libxslt
---> Fetching archive for postgresql_select
---> Attempting to fetch postgresql_select-0.3_0.darwin_17.noarch.tbz2 from https://packages.macports.org/postgresql_select
---> Attempting to fetch postgresql_select-0.3_0.darwin_17.noarch.tbz2.rmd160 from https://packages.macports.org/postgresql_select
---> Installing postgresql_select @0.3_0
---> Activating postgresql_select @0.3_0
---> Cleaning postgresql_select
---> Fetching archive for postgresql96
---> Attempting to fetch postgresql96-9.6.10_0.darwin_17.x86_64.tbz2 from https://packages.macports.org/postgresql96
---> Attempting to fetch postgresql96-9.6.10_0.darwin_17.x86_64.tbz2.rmd160 from https://packages.macports.org/postgresql96
---> Installing postgresql96 @9.6.10_0
---> Activating postgresql96 @9.6.10_0
---> Cleaning postgresql96
---> Fetching archive for postgresql96-server
---> Attempting to fetch postgresql96-server-9.6.10_0.darwin_17.noarch.tbz2 from https://packages.macports.org/postgresql96-server
---> Attempting to fetch postgresql96-server-9.6.10_0.darwin_17.noarch.tbz2.rmd160 from https://packages.macports.org/postgresql96-server
---> Installing postgresql96-server @9.6.10_0
---> Activating postgresql96-server @9.6.10_0
---> Cleaning postgresql96-server
---> Updating database of binaries
---> Updating database of C++ stdlib usage
---> Scanning binaries for linking errors
---> No broken files found.
---> No broken ports found.
---> Some of the ports you installed have notes:
postgresql96 has the following notes:
To use the postgresql server, install the postgresql96-server port
postgresql96-server has the following notes:
To create a database instance, after install do
sudo mkdir -p /opt/local/var/db/postgresql96/defaultdb
sudo chown postgres:postgres /opt/local/var/db/postgresql96/defaultdb
sudo su postgres -c 'cd /opt/local/var/db/postgresql96 && /opt/local/lib/postgresql96/bin/initdb -D /opt/local/var/db/postgresql96/defaultdb'
A startup item has been generated that will aid in starting postgresql96-server with launchd. It is disabled by default. Execute the following command to start it, and to cause it to launch at startup:
sudo port load postgresql96-server
$
$ sudo mkdir -p /opt/local/var/db/postgresql96/defaultdb
$ sudo chown postgres:postgres /opt/local/var/db/postgresql96/defaultdb
$ sudo su postgres -c 'cd /opt/local/var/db/postgresql96 && /opt/local/lib/postgresql96/bin/initdb -D /opt/local/var/db/postgresql96/defaultdb'
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.
fixing permissions on existing directory /opt/local/var/db/postgresql96/defaultdb ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
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:
/opt/local/lib/postgresql96/bin/pg_ctl -D /opt/local/var/db/postgresql96/defaultdb -l logfile start
$
$ sudo su postgres -c '/opt/local/lib/postgresql96/bin/pg_ctl -D /opt/local/var/db/postgresql96/defaultdb -l /opt/local/var/log/postgresql96/postgres.log start &'
server starting
$ sudo -u postgres /opt/local/lib/postgresql96/bin/createuser -d bsnyder
$ sudo -u postgres /opt/local/lib/postgresql96/bin/createdb bsnyder
$ sudo -u postgres /opt/local/lib/postgresql96/bin/psql
postgres=# alter user bsnyder with encrypted password 'bsnyder';
ALTER ROLE
postgres=# grant all privileges on database bsnyder to bsnyder;
GRANT
postgres=# \q
$ /opt/local/lib/postgresql96/bin/psql -U bsnyder
psql (9.6.10)
Type "help" for help.
bsnyder=> select version();
version
-----------------------------------------------------------------------------------------------------------------
PostgreSQL 9.6.10 on x86_64-apple-darwin17.7.0, compiled by Apple LLVM version 9.1.0 (clang-902.0.39.2), 64-bit
(1 row)
bsnyder=> \q
$



BTW, below are the start/stop scripts that I created for PostgreSQL:

#!/bin/sh
sudo su - postgres -c '/opt/local/lib/postgresql96/bin/pg_ctl -D /opt/local/var/db/postgresql96/defaultdb -l /opt/local/var/log/postgresql96/postgres.log start &'
pg_version=$(psql --version | cut -d ' ' -f3)
if [ $? -eq 0 ]; then
echo "PostgreSQL $pg_version started successfully"
exit 0
else
echo "PostgreSQL $pg_version did not start in a timely fashion, please see /opt/local/var/log/postgresql96/postgres.log for details"
exit 1
fi
view raw pg_start.sh hosted with ❤ by GitHub


#!/bin/sh
sudo su - postgres -c '/opt/local/lib/postgresql96/bin/pg_ctl -D /opt/local/var/db/postgresql96/defaultdb -l /opt/local/var/log/postgresql96/postgres.log stop'
pg_version=$(psql --version | cut -d ' ' -f3)
if [ $? -eq 0 ]; then
echo "PostgreSQL $pg_version stopped successfully"
exit 0
else
echo "PostgreSQL $pg_version did not stop in a timely fashion, please see /opt/local/var/log/postgresql96/postgres.log for details"
exit 1
fi
view raw pg_stop.sh hosted with ❤ by GitHub

06 September 2018

GopherCon Denver 2018

Recently I attended GopherCon 2018 in Denver and really enjoyed the whole event. There were about 1500 people there and I really learned a lot. One of my teams writes Kubernetes operators using Golang which got me into writing some Golang myself.

On the first day, we attended a workshop titled Advanced Ultimate Go that was taught by Bill Kennedy from Ardan Labs and it was excellent. Not only is Bill incredibly knowledgeable with Golang (he has years of experience not only in Golang but also in C++) but he is also an extremely good teacher. I learned a lot in a single day and I would have loved to have this class extend for another day or even two.

Coming from a background of mainly Java for 20+ years, the Java community has an amazing piece of engineering in the JVM that handles most performance related concerns for us. We design Java classes however we please and we make use of any data structures we please and never really give it a second thought simply because the JVM handles all the real mechanics for us. With Golang, this is not the case. Although Golang has garbage collection (which is really nice, I hated using malloc() and free() in C) it's very different than what JVM does. Also, in many ways, the Go language is very succinct compared to Java. Both in terms of the amount of code you must write (Golang requires a lot less boilerplate code) to the ease of deployment with Golang (you have a single binary to deploy, no dependencies or CLASSPATH to manage). That being said, I'm still not sure that I would completely switch all web development away from Java to Golang. While the Golang learning curve is a lot easier than Scala, the issue I see are the implications on performance with the code you write. Whereas with Java, while there are performance concerns, as I said above the JVM handles a tremendous amount of things under the covers so that we don't have to care nearly as much.

Having spoken at many, many conferences over the years, I was very pleasantly surprised by the number of female attendees and speakers! I saw more talks delivered by women than I saw delivered by men which was excellent! The community seemed very open and engaging to everyone which I really liked. Being in the software industry for so long, it's still shocking to me how much of it is dominated by males. Anyway, I really enjoyed the cultural and gender diversity at Golang.

There is one minor change that I would like to suggest to the organizers of the Golang conference. Many years ago, I spoke at a conference in Denmark where I first saw this. On tables next to the doors at the back of a room where talks are taking place, there are big glass bowls with three piles of Post-It size paper, each pile a different color -- red, yellow and green. As attendees exit the room, they are asked to grab a single piece of paper in the color that represents how you felt about the presentation/talk. When the talk completes and the room is empty, the conference organizers gather the papers from the bowl, tally them up and provide the stats to the speaker. It's basically like a quick rating of what attendees thought of the talk. This small system does not replace the comment cards that organizers always ask of attendees because this is how attendees elaborate on they rated the talk the way they did. Both systems of rating are important because they deliver two different but equally important types of data to the organizers and the speakers. Anyway, this my two cents.

I really enjoyed GopherCon for a variety of reasons and I would love to attend again. Since the conference I have written a lot more Golang code and the more I write the more I like it. In my mind, Golang should be the goto language for systems programming, DevOps type stuff. While it can easily handle general web development tasks, I'm not sure yet if I would drop Java in favor of Go. I guess I need to keep coding away in both.