Thursday, January 9, 2020

How to Install, Start, Stop & Restart PostgreSQL Server on Windows, Linux, MacOS / OSX


In this post, we are going to figure out how to start, stop, and restart a PostgreSQL server on macOS, Linux, and Windows.
1. On macOS
If you installed PostgreSQL via Homebrew:
  • To start manually:
pg_ctl -D /usr/local/var/postgres start
  • To stop manually:
pg_ctl -D /usr/local/var/postgres stop
  • To start PostgreSQL server now and relaunch at login:
brew services start postgresql
  • And stop PostgreSQL:
brew services stop postgresql

If you want a hassle-free way to manage the local PostgreSQL database servers, use DBngin. It’s just one click to start, another click to turn off. No dependencies, no command line required, multiple drivers, multiple versions and multiple ports. And it’s free.

2. On Windows
Download and install PostgreSQL with Installer or Portable.
First, you need to find the PostgreSQL database directory, it can be something like C:\Program Files\PostgreSQL\10.4\data. Then open Command Prompt and execute this command:
pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" start
  • To stop the server
pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" stop
  • To restart the server:
pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" restart
Another way:
  • Open Run Window by Winkey + R
  • Type services.msc
  • Search Postgres service based on version installed.
  • Click stop, start or restart the service option.

3. On Linux
Update and install PostgreSQL 10.4
sudo apt-get update
sudo apt-get install postgresql-10.4
By default, the postgres user has no password and can hence only connect if ran by the postgres system user. The following command will assign it:
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
sudo -u postgres psql -c "CREATE DATABASE testdb;"
  • Start the PostgreSQL server
sudo service postgresql start
  • Stop the PostgreSQL server:
sudo service postgresql stop

Need a good GUI tool for PostgreSQL on MacOS and Windows? TablePlus is a modern, native tool with an elegant GUI that allows you to simultaneously manage multiple databases such as MySQL, PostgreSQL, SQLite, Microsoft SQL Server and more.


Reference :


Saturday, October 19, 2019

Create Valid SSL / HTTPS Certificate for Locally using mkcert


The web is moving to HTTPS, preventing network attackers from observing or injecting page contents. But HTTPS needs TLS certificates, and while deployment is increasingly a solved issue thanks to the ACME protocol and Let's Encrypt, development still mostly ends up happening over HTTP because no one can get an universally valid certificate for localhost.

This is a problem because more and more browser features are being made available only to secure origins, and testing with HTTP hides any mixed content issues that can break a production HTTPS website. Developing with HTTPS should be as easy as deploying with HTTPS.

That's what mkcert is for.



mkcert is a simple by design tool that hides all the arcane knowledge required to generate valid TLS certificates. It works for any hostname or IP, including localhost, because it only works for you.

Here's the twist: it doesn't generate self-signed certificates, but certificates signed by your own private CA, which your machine is automatically configured to trust when you run mkcert -install. So when your browser loads a certificate generated by your instance of mkcert, it will show up with a green lock!


Quickstart

1. Download mkcert at GitHub FiloSottile

2. Install mkcert
$ mkcert -install
Install the local CA in the system trust store.

3.1 Create Certificate
$ mkcert example.org
Generate "example.org.pem" and "example.org-key.pem".
$ mkcert example.com myapp.dev localhost 127.0.0.1 ::1
Generate "example.com+4.pem" and "example.com+4-key.pem".


3.2 Create Wildcard Ceritificate
$ mkcert '*.example.com'
Generate "_wildcard.example.com.pem" and "_wildcard.example.com-key.pem".


3.3 Create PKCS #12 Certificate (Advanced Options)
$ mkcert -pkcs12 example.com
Generate "example.com.p12" instead of a PEM file.


4. Uninstall Certificate
$ mkcert -uninstall
Uninstall the local CA (but do not delete it).


Reference: