- Mac Os X Set Environment Variable Pgdata For User Postgres 10
- Set Environment Variable Linux
- Set Environment Variable Vista
- Unix Set Environment Variable
- Mac Os X Set Environment Variable Pgdata For User Postgres 1
Jun 20, 2008 The good news is that this is an easy task on Mac OS X. The recommended way is by editing your.bashprofile file. This file is read and the commands in it executed by Bash every time you log in to the system. The best part is that this file is specific to your user so you won’t affect other users on the same system by changing it. Export will set the context for your current session. So we need to hack our terminal so that we will export this PGDATA env variable to every session. If you are using zsh, you can simply execute the below command. Echo 'export PGDATA='/usr/local/var/postgres' /.zshrc. I downloaded postgresql-9.2.4-1-osx.dmg for my Mac OS running with OS X version 10.8.3. Now, let us open the dmg image in finder and just double click it which will give you PostgreSQL installer in the following window − Next, click the postgres-9.2.4-1-osx icon, which will give a warning message. Accept the warning and proceed for further. Postgres95 1994-1995 – New life in the OpenSource world Two Ph.D. Students from Stonebraker's lab, Andrew Yu and Jolly Chen started Postgres95. Postgres' POSTQUEL query language replaced with with an extended subset of SQL. Departed from academia to a new life in the open source world with a group of dedicated developers outside of Berkeley.
The following environment variables can be used to select default connection parameter values, which will be used by
PQconnectdb
, PQsetdbLogin
and PQsetdb
if no value is directly specified by the calling code. These are useful to avoid hard-coding database connection information into simple client applications, for example.- PGHOST behaves the same as the host connection parameter.
- PGHOSTADDR behaves the same as the hostaddr connection parameter. This can be set instead of or in addition to PGHOST to avoid DNS lookup overhead.
- PGPORT behaves the same as the port connection parameter.
- PGDATABASE behaves the same as the dbname connection parameter.
- PGUSER behaves the same as the user connection parameter.
- PGPASSWORD behaves the same as the password connection parameter. Use of this environment variable is not recommended for security reasons, as some operating systems allow non-root users to see process environment variables via ps; instead consider using the ~/.pgpass file (see Section 31.15).
- PGPASSFILE specifies the name of the password file to use for lookups. If not set, it defaults to ~/.pgpass (see Section 31.15).
- PGSERVICE behaves the same as the service connection parameter.
- PGSERVICEFILE specifies the name of the per-user connection service file. If not set, it defaults to ~/.pg_service.conf (see Section 31.16).
- PGOPTIONS behaves the same as the options connection parameter.
- PGAPPNAME behaves the same as the application_name connection parameter.
- PGSSLMODE behaves the same as the sslmode connection parameter.
- PGREQUIRESSL behaves the same as the requiressl connection parameter. This environment variable is deprecated in favor of the PGSSLMODE variable; setting both variables suppresses the effect of this one.
- PGSSLCOMPRESSION behaves the same as the sslcompression connection parameter.
- PGSSLCERT behaves the same as the sslcert connection parameter.
- PGSSLKEY behaves the same as the sslkey connection parameter.
- PGSSLROOTCERT behaves the same as the sslrootcert connection parameter.
- PGSSLCRL behaves the same as the sslcrl connection parameter.
- PGREQUIREPEER behaves the same as the requirepeer connection parameter.
- PGKRBSRVNAME behaves the same as the krbsrvname connection parameter.
- PGGSSLIB behaves the same as the gsslib connection parameter.
- PGCONNECT_TIMEOUT behaves the same as the connect_timeout connection parameter.
- PGCLIENTENCODING behaves the same as the client_encoding connection parameter.
The following environment variables can be used to specify default behavior for each PostgreSQL session. (See also the ALTER ROLE and ALTER DATABASE commands for ways to set default behavior on a per-user or per-database basis.)
- PGDATESTYLE sets the default style of date/time representation. (Equivalent to SET datestyle TO ...)
- PGTZ sets the default time zone. (Equivalent to SET timezone TO ...)
- PGGEQO sets the default mode for the genetic query optimizer. (Equivalent to SET geqo TO ...)
Install eclipse for python mac os x lion. Refer to the SQL command SET for information on correct values for these environment variables.
The following environment variables determine internal behavior of libpq; they override compiled-in defaults.
- PGSYSCONFDIR sets the directory containing the pg_service.conf file and in a future version possibly other system-wide configuration files.
- PGLOCALEDIR sets the directory containing the locale files for message localization.
[ Download from release page ]
The release page has pre-compiled binaries for Mac OS X, Windows, and several Linux distributions. Extract the tarball and run the binary inside with the
--help
flag to see usage instructions:Note
If you see a dialog box like this on Windows, it may be that the
pg_config
program is not in your system path.It usually lives in
C:ProgramFilesPostgreSQL<version>bin
. See this article about how to modify the system path.To use PostgREST you will need an underlying database (PostgreSQL version 9.5 or greater is required). You can use something like Amazon RDS but installing your own locally is cheaper and more convenient for development.
On Windows, PostgREST will fail to run unless the PostgreSQL binaries are on the system path. To test whether this is the case, run
pg_config
from the command line. You should see it output a list of paths.The PostgREST server reads a configuration file to determine information about the database and how to serve client requests. There is no predefined location for this file, you must specify the file path as the one and only argument to the server:
The file must contain a set of key value pairs. At minimum you must include these keys:
The user specified in the db-uri is also known as the authenticator role. For more information about the anonymous vs authenticator roles see the Overview of Role System.
Here is the full list of configuration parameters. Quicktime 7 pro for mac os x free.
Name | Type | Default | Required |
---|---|---|---|
db-uri | String | Y | |
db-schema | String | Y | |
db-anon-role | String | Y | |
db-pool | Int | 10 | |
db-extra-search-path | String | public | |
server-host | String | 127.0.0.1 | |
server-port | Int | 3000 | |
server-proxy-uri | String | ||
jwt-secret | String | ||
jwt-aud | String | ||
secret-is-base64 | Bool | False | |
max-rows | Int | ∞ | |
pre-request | String | ||
app.settings.* | String | ||
role-claim-key | String | .role |
db-uri¶
The standard connection PostgreSQL URI format. Symbols and unusual characters in the password or other fields should be percent encoded to avoid a parse error. If enforcing an SSL connection to the database is required you can use sslmode in the URI, for example
postgres://user:pass@host:5432/dbname?sslmode=require
.When running PostgREST on the same machine as PostgreSQL, it is also possible to connect to the database using a Unix socket and the Peer Authentication method as an alternative to TCP/IP communication and authentication with a password, this also grants higher performance. To do this you can omit the host and the password, e.g.
postgres://user@/dbname
, see the libpq connection string documentation for more details.On older systems like Centos 6, with older versions of libpq, a different db-uri syntax has to be used. In this case the URI is a string of space separated key-value pairs (key=value), so the example above would be
'host=hostuser=userport=5432dbname=dbnamepassword=pass'
.Choosing a value for this parameter beginning with the at sign such as
@filename
(e.g. @./configs/my-config
) loads the secret out of an external file.db-schema¶
The database schema to expose to REST clients. Tables, views and stored procedures in this schema will get API endpoints.
This schema gets added to the search_path of every request.
db-anon-role¶
The database role to use when executing commands on behalf of unauthenticated clients.
db-pool¶
Number of connections to keep open in PostgREST’s database pool. Having enough here for the maximum expected simultaneous client connections can improve performance. Note it’s pointless to set this higher than the
max_connections
GUC in your database.db-extra-search-path¶
Extra schemas to add to the search_path of every request. These schemas tables, views and stored procedures don’t get API endpoints, they can only be referred from the database objects exposed in your db-schema.
Multiple schemas can be added in a comma-separated string, e.g.
public,extensions
.server-host¶
Where to bind the PostgREST web server. In addition to the usual address options, PostgREST interprets these reserved addresses with special meanings:
*
- any IPv4 or IPv6 hostname*4
- any IPv4 or IPv6 hostname, IPv4 preferred!4
- any IPv4 hostname*6
- any IPv4 or IPv6 hostname, IPv6 preferred!6
- any IPv6 hostname
server-proxy-uri¶
Overrides the base URL used within the OpenAPI self-documentation hosted at the API root path. Use a complete URI syntax
scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
. Ex. https://postgrest.com
jwt-secret¶
The secret or JSON Web Key (JWK) (or set) used to decode JWT tokens clients provide for authentication. For security the key must be at least 32 characters long. If this parameter is not specified then PostgREST refuses authentication requests. Choosing a value for this parameter beginning with the at sign such as
@filename
loads the secret out of an external file. This is useful for automating deployments. Note that any binary secrets must be base64 encoded. Both symmetric and asymmetric cryptography are supported. For more info see Asymmetric Keys.jwt-aud¶
Specifies the JWT audience claim. If this claim is present in the client provided JWT then you must set this to the same value as in the JWT, otherwise verifying the JWT will fail.
secret-is-base64¶
When this is set to
true
, the value derived from jwt-secret
will be treated as a base64 encoded secret.max-rows¶
A hard limit to the number of rows PostgREST will fetch from a view, table, or stored procedure. Limits payload size for accidental or malicious requests.
pre-request¶
A schema-qualified stored procedure name to call right after switching roles for a client request. This provides an opportunity to modify SQL variables or raise an exception to prevent the request from completing.
app.settings.*¶
Arbitrary settings that can be used to pass in secret keys directly as strings, or via OS environment variables. For instance:
app.settings.jwt_secret='$(MYAPP_JWT_SECRET)'
will take MYAPP_JWT_SECRET
from the environment and make it available to postgresql functions as current_setting('app.settings.jwt_secret')
.role-claim-key¶
A JSPath DSL that specifies the location of the
role
key in the JWT claims. This can be used to consume a JWT provided by a third party service like Auth0, Okta or Keycloak. Usage examples:PostgREST outputs basic request logging to stdout. When running it in an SSH session you must detach it from stdout or it will be terminated when the session closes. The easiest technique is redirecting the output to a log file or to the syslog:
(Avoid
nohuppostgrest
because the HUP signal is used for manual Schema Reloading.) https://albumgreat101.weebly.com/blog/older-maya-for-75-mac-os-x.You can get the official PostgREST Docker image with:
The image consults an internal
/etc/postgrest.conf
file. To customize this file you can either mount a replacement configuration file into the container, or use environment variables. The environment variables will be interpolated into the default config file.These variables match the options shown in our Configuration section, except they are capitalized, have a
PGRST_
prefix, and use underscores. To get a list of the available environment variables, run this:There are two ways to run the PostgREST container: with an existing external database, or through docker-compose.
Containerized PostgREST with native PostgreSQL¶
Mac Os X Set Environment Variable Pgdata For User Postgres 10
The first way to run PostgREST in Docker is to connect it to an existing native database on the host.
The database connection string above is just an example. Adjust the role and password as necessary. You may need to edit PostgreSQL’s
pg_hba.conf
to grant the user local login access.Note
Docker on Mac does not support the
--net=host
flag. Instead you’ll need to create an IP address alias to the host. Requests for the IP address from inside the container are unable to resolve and fall back to resolution by the host.You should then use 10.0.0.10 as the host in your database connection string. Also remember to include the IP address in the
listen_address
within postgresql.conf. For instance:Containerized PostgREST and db with docker-compose¶
Set Environment Variable Linux
To avoid having to install the database at all, you can run both it and the server in containers and link them together with docker-compose. Use this configuration:
Go into the directory where you saved this file and run
docker-composeup
. You will see the logs of both the database and PostgREST, and be able to access the latter on port 3000.If you want to have a visual overview of your API in your browser you can add swagger-ui to your
docker-compose.yml
:With this you can see the swagger-ui in your browser on port 8080.
Assuming your making modifications locally and then pushing to GitHub, it’s easy to deploy to Heroku.
- Create a new app on Heroku
- In Settings add the following buildpack
https://github.com/PostgREST/postgrest-heroku
- Add the require Config Vars in Heroku (see https://github.com/PostgREST/postgrest/blob/master/app.json#L7-L57 for more details)
- Modify your postgrest.conf file as required to match your Config Vars in Heroku
- Create your
Procfile
and add./env-to-config./postgrestpostgrest.conf
- Push your changes to GitHub
- Set Heroku to automatically deploy from Master and then manually deploy the branch for the first build
Note
We discourage building and using PostgREST on Alpine Linux because of a reported GHC memory leak on that platform.
When a pre-built binary does not exist for your system you can build the project from source. You’ll also need to do this if you want to help with development. Stack makes it easy. It will install any necessary Haskell dependencies on your system.
- Install Stack for your platform
- Install Library Dependencies
Operating System Dependencies Ubuntu/Debian libpq-dev, libgmp-dev CentOS/Fedora/Red Hat postgresql-devel, zlib-devel, gmp-devel BSD postgresql95-client OS X libpq, gmp - Build and install binary
Note
If building fails and your system has less than 1GB of memory, try adding a swap file.
- Check that the server is installed:
postgrest--help
.
PostgREST Test Suite¶
Creating the Test Database¶
To properly run postgrest tests one needs to create a database. To do so, use the test creation script
create_test_database
in the test/
folder.Set Environment Variable Vista
The script expects the following parameters:
Use the connection URI to specify the user, password, host, and port. Do not provide the database in the connection URI. The PostgreSQL role you are using to connect must be capable of creating new databases.
The
database_name
is the name of the database that stacktest
will connect to. If the database of the same name already exists on the server, the script will first drop it and then re-create it.Optionally, specify the database user
stacktest
will use. The user will be given necessary permissions to reset the database after every test run.If the user is not specified, the script will generate the role name
postgrest_test_
suffixed by the chosen database name, and will generate a random password for it.Optionally, if specifying an existing user to be used for the test connection, one can specify the password the user has.
The script will return the db uri to use in the tests–this uri corresponds to the
db-uri
parameter in the configuration file that one would use in production.Generating the user and the password allows one to create the database and run the tests against any PostgreSQL server without any modifications to the server. (Such as allowing accounts without a password or setting up trust authentication, or requiring the server to be on the same localhost the tests are run from).
Running the Tests¶
To run the tests, one must supply the database uri in the environment variable
POSTGREST_TEST_CONNECTION
.Typically, one would create the database and run the test in the same command line, using the postgres superuser:
For repeated runs on the same database, one should export the connection variable:
If the environment variable is empty or not specified, then the test runner will default to connection uri
Unix Set Environment Variable
This connection assumes the test server on the
localhost:code:
with the user postgrest_test without the password and the database of the same name.Destroying the Database¶
The test database will remain after the test, together with four new roles created on the PostgreSQL server. To permanently erase the created database and the roles, run the script
test/delete_test_database
, using the same superuser role used for creating the database:Testing with Docker¶
The ability to connect to non-local PostgreSQL simplifies the test setup. One elegant way of testing is to use a disposable PostgreSQL in docker.
For example, if local development is on a mac with Docker for Mac installed:
Additionally, if one creates a docker container to run stack test (this is necessary on Mac OS Sierra with GHC below 8.0.1, where
stacktest
fails), one can run PostgreSQL in a separate linked container, or use the locally installed PostgreSQL app.Build the test container with
test/Dockerfile.test
:The first run of the test container will take a long time while the dependencies get cached. Creating the
~/.stack-linux
folder and mapping it as a volume into the container ensures that we can run the container in disposable mode and not worry about subsequent runs being slow. .stack-work-docker
is also mapped into the container and must be specified when using stack from Linux, not to interfere with the .stack-work
for local development. (On Sierra, stackbuild
works, while stacktest
fails with GHC 8.0.1).Linked containers:
Mac Os X Set Environment Variable Pgdata For User Postgres 1
Stack test in Docker for Mac, PostgreSQL app on mac: