Uncategorized

Postgres.app

YOU ARE READING: Postgres.app AT Vccidata_En

Postgres.app is a full-featured PostgreSQL installation packaged as a standard Mac app. It comes with everything you need to get started, and we’ve even included the popular PostGIS geospatial extension.

Postgres.app has a nice interface and a handy menu bar item. You never have to touch the command line to use it – but of course we include all the necessary command line tools and header files for advanced users.

Reading: How to create an app psql

Postgres.app can install minor updates automatically so you can get bug fixes as soon as possible.

Install Postgres.app

  • Download ➜ Move to Applications folder ➜ Double-click

    If not If you have Postgres .app to the Applications folder, you will see a warning about an unidentified developer and will not be able to open it.

  • Click “Initialize” to create a new server

  • Configure your $PATH to use the included command line tools (optional):

    sudo mkdir -p /etc/paths.d &&echo /Applications/Postgres .app /Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp

Done! Your Mac is now running a PostgreSQL server with these default settings:

host localhost port 5432 user your system username database same as user password no connection url postgresql://localhost

To connect to psql, duplicate Click on a database. To connect directly from the command line, type psql. If you prefer to use a graphical client, see below.

NOTE: These instructions assume you have never installed PostgreSQL on your Mac before. If you previously installed PostgreSQL using Homebrew, MacPorts, and the EnterpriseDB installer, you should remove other PostgreSQL installations first. We also have instructions for upgrading from older versions of Postgres.app.

Graphical Clients

Postgres.app includes psql, a versatile command line client for PostgreSQL. But it’s not the only option; There are many great graphical clients for PostgreSQL. Two popular tools are:

  • pgAdmin 4
  • Postico

pgAdmin 4 is a feature-rich, open-source PostgreSQL client. It supports almost all features in PostgreSQL. The only downside is that the cross-platform UI really doesn’t live up to expectations of a native Mac app.

Postico, on the other hand, is a very modern Mac app. It’s made by the same people who maintain Postgres.app and we think you’ll like it! We put a lot of effort into making it a pleasure to use. However, it doesn’t have the extensive features of pgAdmin and is more of a commercial app than open source.

Apart from these two options, there’s a lot more to choose from! See the documentation for a list of great Mac apps for PostgreSQL.

Connect

See also: How to Code a Website

Once your PostgreSQL server is up and running, you’ll probably want to log out of your application. To connect to PostgreSQL from popular programming languages ​​and frameworks:

PHP

To connect from PHP, make sure it supports PostgreSQL. The version included with macOS does not support PostgreSQL. We recommend MAMP for an easy way to install a recent version of PHP that works.

You can use PDO (object oriented):

prepare(“SELECT dataname FROM pg_database”); $statement->execute(); while ($row = $statement->fetch()) { echo “

” . htmlspecialchars($row[“dataname”]) . “

“; } ?>

Or the pg_connect() functions (procedural):

<?php $conn = pg_connect("host=localhost"); $result = pg_query($conn, "SELECT dataname FROM pg_database "); while ($row = pg_fetch_row($result)) { echo "

” . htmlspecialchars($row[0]) . “

“; } ?> Python

To connect to a PostgreSQL server with Python, please install the psycopg2 library first:

pip install psycopg2

Django

Add in your settings.py an entry for your DATABASES setting:

DATABASES = { “default”: { “ENGINE”: “django.db.backends.postgresql_psycopg2”, “NAME”: “[YOUR_DATABASE_NAME]”, ” USER”: “[YOUR_USER_NAME ]”, “PASSWORD”: “”, “HOST”: “localhost”, “PORT”: “”, } }

Flask

If you use the Flask-SQLAlchemy extension, you can use your application code:

from Flask Import Flask from Flask_sqlalchemy Import SQLAlchemy app = Flask(__name__) app.config[‘SQLALCHEMY_DATABASE_URI’] = ‘postgresql://localhost/[YOUR_DATABASE_NAME]’ db = SQLAlchemy (app)

SQLAlchemy

from sqlalchemy import create_engine engine = create_engine(‘postgresql://localhost/[YOUR_DATABASE_NAME]’) Ruby

To install the pg gem, make sure you include $ PATH set up correctly (see Command-Line Tools) and then run the following command:

sudo ARCHFLAGS=”-arch x 86_64″ gem install pg

Rails

In config/database.yml use the following settings:

development: adapter: postgresql database: [YOUR_DATABASE_NAME] host: localhost

Sinatra

In config.ru or your application code:

set :database, “postgres://localhost/[YOUR_DATABASE_NAME]”

ActiveRecord

Install the ActiveRecord gem and request ‘active_record’ and set it up a database connection:

ActiveRecord::Base.establish_connection(“postgres://localhost/[YOUR_DATABASE_NAME]”)

DataMapper

Install and require the Gems datamapper and do_postgres and create a database connection :

DataMapper.setup(:default, “postgres://localhost/[YOUR_DATABASE_NAME]”)

Sequel

See also: Wiki Requirements/Using HTML, CSS, and Javascript

Install and require the Sequel gem and build a database connection:

DB = Sequel.connect(“postgres://localhost/[YOUR_DATABASE_NAME]”) Java

  1. Download and install the PostgreSQL JDBC driver
  2. Connect to the JDBC URL jdbc:postgresql://localhost

For more information, see the official PostgreSQL JDBC documentation.

C

libpq is the native C client library for connecting to PostgreSQL. It’s really easy to use:

#include int main() { PGconn *conn = PQconnectdb(“postgresql://localhost”); if (PQstatus(conn) == CONNECTION_OK) {PGresult *result = PQexec(conn, “SELECT dataname FROM pg_database”); for (int i = 0; i < PQntuples(result); i++) { char *value = PQgetvalue(result, i, 0); if (value) printf("%s
", value); } PQclear(result); } PQfinish(conn); }

Now compile and run the file with clang:

clang main.c -I$(pg_config -includedir) -L$ (pg_config -libdir) -lpq ./a.out Swift

You can just use the C API in Swift First add libpq in your bridging header:

#import

Then make sure you link with libpq.

On iOS, you need to build libpq yourself.

On macOS, you can use the system-provided libpq (supported no SSL) or use libpq provided by Postgres.app by adding the following build settings:

other linker flags -lpq header search paths /Applications/Postgres.app/Contents/Versions/ latest/include Library Search Paths /Applications/Postgres.app/ Contents/Versions/latest/lib

Now you can use the libpq C library to connect to PostgreSQL:

let conn = PQconnectdb(” postgresql://localh ost”.cString(using: .utf8)) if PQstatus (conn) == CONNECTION_OK {let result = PQexec(conn, “SELECT dataname FROM pg_database WHERE datalowconn”) for i in 0 ..< PQntuples(result) { guard let value = PQgetvalue(result, i, 0) else { Continue } let dbname = String(cString: value) print(dbname) } PQclear(result) } PQfinish(conn)

Support

We have see the Troubleshooting section of the documentation for a list of common issues.

For general PostgreSQL questions, see the official PostgreSQL documentation.

If you have a question about Postgres.app If you have a problem that isn’t answered by the Postgres.app documentation, you can ask @PostgresApp on Twitter or open an issue on GitHub.

If you’re reporting bugs, let us know which version of Postgres .app and macOS you are using and make sure to include detailed error messages even if your problem seems similar to another.

License

Postgres.app , PostgreSQL and its extensions are released under the PostgreSQL License. The released binaries also include OpenSSL (OpenSSL license), PostGIS (GPLv2) and plv8 (3 clause BSD).

Postgres.app is maintained by Jakob Egger and Tobias Bussman. It was originally created by Mattt Thompson.

See also: How to Set Up a Group Blog

.

See also  How To Create A Samsung Account And Set Up Gear VR

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button