https://wiki.archlinux.org/api.php?action=feedcontributions&user=Caseyclysm&feedformat=atomArchWiki - User contributions [en]2024-03-29T10:39:08ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=PostgreSQL&diff=494251PostgreSQL2017-10-28T16:18:48Z<p>Caseyclysm: /* Administration tools */ Updated package to pgAdmin4. pgAdmin3 is no longer supported.</p>
<hr />
<div>[[Category:Database management systems]]<br />
[[it:PostgreSQL]]<br />
[[ja:PostgreSQL]]<br />
[[ru:PostgreSQL]]<br />
[[zh-hans:PostgreSQL]]<br />
{{Related articles start}}<br />
{{Related|PhpPgAdmin}}<br />
{{Related articles end}}<br />
[http://www.postgresql.org/ PostgreSQL] is an open source, community driven, standard compliant object-relational database system.<br />
<br />
This document describes how to set up PostgreSQL. It also describes how to configure PostgreSQL to be accessible from a remote client. Among other applications, PostgreSQL can be substituted for MySQL as part of the [[LAMP]] web stack.<br />
<br />
== Installing PostgreSQL ==<br />
<br />
[[Install]] the {{Pkg|postgresql}} package. Then [[Users_and_groups#Other_examples_of_user_management|set a password]] for the newly created ''postgres'' user.<br />
<br />
Then, switch to the default PostgreSQL user ''postgres'' by executing the following command:<br />
<br />
* If you have [[sudo]] and your username is in {{ic|sudoers}}:<br />
<br />
:{{bc|$ sudo -u postgres -i}}<br />
<br />
* Otherwise:<br />
<br />
:{{bc|<nowiki><br />
$ su<br />
# su -l postgres<br />
</nowiki>}}<br />
<br />
See {{man|1|su}} or {{man|8|sudo}} for their usage.<br />
<br />
{{Note|Commands that should be run as the postgres user are prefixed by {{ic|[postgres]$}} in this article.}}<br />
<br />
Before PostgreSQL can function correctly, the database cluster must be initialized:<br />
<br />
[postgres]$ initdb --locale $LANG -E UTF8 -D '/var/lib/postgres/data'<br />
<br />
Where:<br />
<br />
* the {{ic|--locale}} is the one defined in the file {{ic|/etc/locale.conf}};<br />
* the {{ic|-E}} is the default encoding of the database that will be created in the future;<br />
* and {{ic|-D}} is the default location where the database cluster must be stored.<br />
<br />
Many lines should now appear on the screen with several ending by {{ic|... ok}}:<br />
{{bc|<br />
The files belonging to this database system will be owned by user "postgres".<br />
This user must also own the server process.<br />
<br />
The database cluster will be initialized with locale "en_GB.UTF-8".<br />
The default text search configuration will be set to "english".<br />
<br />
Data page checksums are disabled.<br />
<br />
fixing permissions on existing directory /var/lib/postgres/data ... ok<br />
creating subdirectories ... ok<br />
selecting default max_connections ... 100<br />
selecting default shared_buffers ... 128MB<br />
selecting dynamic shared memory implementation ... posix<br />
creating configuration files ... ok<br />
creating template1 database in /var/lib/postgres/data/base/1 ... ok<br />
initializing pg_authid ... ok<br />
[...]<br />
}}<br />
<br />
If these are the kind of lines you see, then the process succeeded. Return to the regular user using {{ic|exit}}.<br />
<br />
As root, [[start]] and [[enable]] {{ic|postgresql.service}}.<br />
<br />
{{Tip|If you change the root to something other than {{ic|/var/lib/postgres}}, you will have to [[edit]] the service file. If the root is under {{ic|home}}, make sure to set {{ic|ProtectHome}} to false.}}<br />
<br />
{{Warning|If the database resides on a [[Btrfs]] file system, you should consider disabling [[Btrfs#Copy-on-Write (CoW)|Copy-on-Write]] for the directory before creating any database. If the database resides on a [[ZFS]] file system, you should consult [[ZFS#Database]] before creating any database.}}<br />
<br />
== Create your first database/user ==<br />
<br />
{{Tip|If you create a PostgreSQL user with the same name as your Linux username, it allows you to access the PostgreSQL database shell without having to specify a user to login (which makes it quite convenient).}}<br />
<br />
Become the postgres user. Add a new database user using the [http://www.postgresql.org/docs/current/static/app-createuser.html createuser] command:<br />
<br />
[postgres]$ createuser --interactive<br />
<br />
Create a new database over which the above user has read/write privileges using the [http://www.postgresql.org/docs/current/static/app-createdb.html createdb] command (execute this command from your login shell if the database user has the same name as your Linux user, otherwise add {{ic|-U ''database-username''}} to the following command):<br />
<br />
$ createdb myDatabaseName<br />
<br />
== Familiarize with PostgreSQL ==<br />
<br />
=== Access the database shell ===<br />
<br />
Become the postgres user. Start the primary database shell, [http://www.postgresql.org/docs/current/static/app-psql.html psql], where you can do all your creation of databases/tables, deletion, set permissions, and run raw SQL commands. Use the {{ic|-d}} option to connect to the database you created (without specifying a database, {{ic|psql}} will try to access a database that matches your username).<br />
<br />
[postgres]$ psql -d myDatabaseName<br />
<br />
Some helpful commands:<br />
<br />
Get help:<br />
<br />
=> \help<br />
<br />
Connect to a particular database:<br />
<br />
=> \c <database><br />
<br />
List all users and their permission levels:<br />
<br />
=> \du<br />
<br />
Show summary information about all tables in the current database:<br />
<br />
=> \dt<br />
<br />
Exit/quit the {{ic|psql}} shell:<br />
<br />
=> \q or CTRL+d<br />
<br />
There are of course many more meta-commands, but these should help you get started. To see all meta-commands run: <br />
<br />
=> \?<br />
<br />
== Optional configuration ==<br />
<br />
=== Configure PostgreSQL to be accessible from remote hosts ===<br />
<br />
The PostgreSQL database server configuration file is {{ic|postgresql.conf}}. This file is located in the data directory of the server, typically {{ic|/var/lib/postgres/data}}. This folder also houses the other main configuration files, including the {{ic|pg_hba.conf}}.<br />
<br />
{{Note|By default, this folder will not be browsable or searchable by a regular user. This is why {{ic|find}} and {{ic|locate}} are not finding the configuration files.}}<br />
<br />
Edit the file {{ic|/var/lib/postgres/data/postgresql.conf}}. In the connections and authentications section, add the {{ic|listen_addresses}} line to your needs:<br />
<br />
listen_addresses = 'localhost,''my_local_ip_address'''<br />
#You can use '*' to listen on all local addresses<br />
<br />
Take a careful look at the other lines.<br />
<br />
Host-based authentication is configured in {{ic|/var/lib/postgres/data/pg_hba.conf}}. This file controls which hosts are allowed to connect. Note that the defaults '''allow any local user to connect as any database user''', including the database superuser. Add a line like the following:<br />
<br />
# IPv4 local connections:<br />
host all all ''my_remote_client_ip_address''/32 md5<br />
<br />
where {{ic|my_remote_client_ip_address}} is the IP address of the client.<br />
<br />
See the documentation for [http://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html pg_hba.conf].<br />
<br />
After this you should [[restart]] {{ic|postgresql.service}} for the changes to take effect.<br />
<br />
{{Note|PostgreSQL uses port {{ic|5432}} by default for remote connections. Make sure this port is open and able to receive incoming connections.}}<br />
<br />
For troubleshooting take a look in the server log file:<br />
<br />
$ journalctl -u postgresql<br />
<br />
=== Configure PostgreSQL authenticate against PAM ===<br />
<br />
PostgreSQL offers a number of authentication methods. If you would like to allow users to authenticate with their system password, additional steps are necessary. First you need to enable [[PAM]] for the connection.<br />
<br />
For example, the same configuration as above, but with PAM enabled:<br />
<br />
# IPv4 local connections:<br />
host all all ''my_remote_client_ip_address''/32 pam<br />
<br />
The PostgreSQL server is however running without root privileges and will not be able to access {{ic|/etc/shadow}}. We can work around that by allowing the postgres group to access this file:<br />
<br />
setfacl -m g:postgres:r /etc/shadow<br />
<br />
=== Change default data directory ===<br />
<br />
The default directory where all your newly created databases will be stored is {{ic|/var/lib/postgres/data}}. To change this, follow these steps:<br />
<br />
Create the new directory and make the postgres user its owner:<br />
<br />
# mkdir -p /pathto/pgroot/data<br />
# chown -R postgres:postgres /pathto/pgroot<br />
<br />
Become the postgres user, and initialize the new cluster:<br />
<br />
[postgres]$ initdb -D /pathto/pgroot/data<br />
<br />
[[Edit]] {{ic|postgresql.service}} to create a drop-in file and override the {{ic|Environment}} and {{ic|PIDFile}} settings. For example:<br />
<br />
[Service]<br />
Environment=PGROOT=''/pathto/pgroot''<br />
PIDFile=''/pathto/pgroot/''data/postmaster.pid<br />
<br />
If you want to use {{ic|/home}} directory for default directory or for tablespaces, add one more line in this file:<br />
<br />
ProtectHome=false<br />
<br />
=== Change default encoding of new databases to UTF-8 ===<br />
<br />
{{Note|If you ran {{ic|initdb}} with {{ic|-E UTF8}} these steps are not required.}}<br />
<br />
When creating a new database (e.g. with {{ic|createdb blog}}) PostgreSQL actually copies a template database. There are two predefined templates: {{ic|template0}} is vanilla, while {{ic|template1}} is meant as an on-site template changeable by the administrator and is used by default. In order to change the encoding of a new database, one of the options is to change on-site {{ic|template1}}. To do this, log into PostgreSQL shell ({{ic|psql}}) and execute the following:<br />
<br />
First, we need to drop {{ic|template1}}. Templates cannot be dropped, so we first modify it so it is an ordinary database:<br />
<br />
UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';<br />
<br />
Now we can drop it:<br />
<br />
DROP DATABASE template1;<br />
<br />
The next step is to create a new database from {{ic|template0}}, with a new default encoding:<br />
<br />
CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE';<br />
<br />
Now modify {{ic|template1}} so it is actually a template:<br />
<br />
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';<br />
<br />
Optionally, if you do not want anyone connecting to this template, set {{ic|datallowconn}} to {{ic|FALSE}}:<br />
<br />
UPDATE pg_database SET datallowconn = FALSE WHERE datname = 'template1';<br />
<br />
{{Note|This last step can create problems when upgrading via {{ic|pg_upgrade}}.}}<br />
<br />
Now you can create a new database:<br />
<br />
[postgres]$ createdb blog<br />
<br />
If you log back in to {{ic|psql}} and check the databases, you should see the proper encoding of your new database:<br />
<br />
{{hc|\l|<nowiki><br />
List of databases<br />
Name | Owner | Encoding | Collation | Ctype | Access privileges<br />
-----------+----------+-----------+-----------+-------+----------------------<br />
blog | postgres | UTF8 | C | C |<br />
postgres | postgres | SQL_ASCII | C | C |<br />
template0 | postgres | SQL_ASCII | C | C | =c/postgres<br />
: postgres=CTc/postgres<br />
template1 | postgres | UTF8 | C | C |<br />
</nowiki>}}<br />
<br />
== Administration tools ==<br />
<br />
* {{App|[[phpPgAdmin]]|Web-based administration tool for PostgreSQL.|http://phppgadmin.sourceforge.net|{{Pkg|phppgadmin}}}}<br />
* {{App|pgAdmin|GUI-based administration tool for PostgreSQL.|http://www.pgadmin.org/|{{Pkg|pgadmin4}}}}<br />
<br />
== Setup HHVM to work with PostgreSQL ==<br />
<br />
{{Out of date|hhvm-pgsql fails to compile against HHVM 3.7.0, but upstream has not resolved the problem yet. See https://github.com/PocketRent/hhvm-pgsql/issues/82|section=Setting up HHVM}}<br />
<br />
$ git clone https://github.com/PocketRent/hhvm-pgsql.git<br />
$ cd hhvm-pgsql<br />
<br />
If you do not use a nightly build, then run this command (verified on HHVM 3.6.1) to avoid compile errors:<br />
<br />
$ git checkout tags/3.6.0<br />
<br />
Then build the extension (if you do not need an improved support for Hack language, then remove -DHACK_FRIENDLY=ON):<br />
<br />
$ hphpize<br />
$ cmake -DHACK_FRIENDLY=ON .<br />
$ make<br />
<br />
Then copy the built extension:<br />
<br />
# cp pgsql.so /etc/hhvm/<br />
<br />
Add to /etc/hhvm/server.ini:<br />
<br />
extension_dir = /etc/hhvm<br />
hhvm.extensions[pgsql] = pgsql.so<br />
<br />
== Upgrading PostgreSQL ==<br />
<br />
Upgrading major PostgreSQL versions (i.e. from {{ic|9.''x''}} to {{ic|9.''y''}}) requires some extra maintenance.<br />
<br />
{{Note|Official PostgreSQL [http://www.postgresql.org/docs/current/static/upgrading.html upgrade documentation] should be followed.}}<br />
<br />
{{Warning|The following instructions could cause data loss. '''Use at your own risk'''.}}<br />
<br />
It is recommended to add the following to your {{ic|/etc/pacman.conf}} file:<br />
<br />
IgnorePkg = postgresql postgresql-libs<br />
<br />
This will ensure you do not accidentally upgrade the database to an incompatible version. When an upgrade is available, pacman will notify you that it is skipping the upgrade because of the entry in {{ic|pacman.conf}}. Minor version upgrades (e.g. 9.0.3 to 9.0.4) are safe to perform. However, if you do an accidental upgrade to a different major version (e.g. 9.0.x to 9.1.x), you might not be able to access any of your data. Always check the [http://www.postgresql.org/ PostgreSQL home page] to be sure of what steps are required for each upgrade. For a bit about why this is the case, see the [http://www.postgresql.org/support/versioning versioning policy].<br />
<br />
There are two main ways to upgrade your PostgreSQL database. Read the official documentation for details.<br />
<br />
For those wishing to use {{ic|pg_upgrade}}, a {{Pkg|postgresql-old-upgrade}} package is available that will always run one major version behind the real PostgreSQL package. This can be installed side-by-side with the new version of PostgreSQL. <br />
<br />
When you are ready, upgrade the following packages: {{Pkg|postgresql}}, {{Pkg|postgresql-libs}}, and {{Pkg|postgresql-old-upgrade}}. Note that the data directory does not change from version to version, so before running {{ic|pg_upgrade}}, it is necessary to rename your existing data directory and migrate into a new directory. The new database must be initialized, as described near the top of this page.<br />
<br />
# systemctl stop postgresql.service<br />
# su -l postgres -c 'mv /var/lib/postgres/data /var/lib/postgres/olddata'<br />
# su -l postgres -c 'initdb --locale en_US.UTF-8 -E UTF8 -D /var/lib/postgres/data'<br />
<br />
The upgrade invocation will likely look something like the following. '''Do not run this command blindly without understanding what it does!''' Reference the [http://www.postgresql.org/docs/current/static/pgupgrade.html upstream pg_upgrade documentation] for details.<br />
<br />
# su -l postgres -c 'pg_upgrade -d /var/lib/postgres/olddata/ -D /var/lib/postgres/data/ -b /opt/pgsql-9.4/bin/ -B /usr/bin/'<br />
<br />
=== Manual dump and reload ===<br />
<br />
You could also do something like this (after the upgrade and install of {{Pkg|postgresql-old-upgrade}}).<br />
<br />
{{Note|Below are the commands for PostgreSQL 9.4. You can find similar commands in {{ic|/opt/}} for PostgreSQL 9.2.}}<br />
<br />
# systemctl stop postgresql.service<br />
# /opt/pgsql-9.4/bin/pg_ctl -D /var/lib/postgres/olddata/ start<br />
# /opt/pgsql-9.4/bin/pg_dumpall >> old_backup.sql<br />
# /opt/pgsql-9.4/bin/pg_ctl -D /var/lib/postgres/olddata/ stop<br />
# systemctl start postgresql.service<br />
# psql -f old_backup.sql postgres<br />
<br />
== Troubleshooting ==<br />
<br />
=== Improve performance of small transactions ===<br />
<br />
If you are using PostgresSQL on a local machine for development and it seems slow, you could try turning [http://www.postgresql.org/docs/current/static/runtime-config-wal.html#GUC-SYNCHRONOUS-COMMIT synchronous_commit off] in the configuration. Beware of the [http://www.postgresql.org/docs/current/static/runtime-config-wal.html#GUC-SYNCHRONOUS-COMMIT caveats], however.<br />
<br />
{{hc|/var/lib/postgres/data/postgresql.conf|2=<br />
synchronous_commit = off<br />
}}<br />
<br />
=== Prevent disk writes when idle ===<br />
<br />
PostgreSQL periodically updates its internal "statistics" file. By default, this file is stored on disk, which prevents disks from spinning down on laptops and causes hard drive seek noise. It is simple and safe to relocate this file to a memory-only file system with the following configuration option:<br />
<br />
{{hc|/var/lib/postgres/data/postgresql.conf|2=<br />
stats_temp_directory = '/run/postgresql'<br />
}}<br />
<br />
=== Cannot connect to database through pg_connect() ===<br />
<br />
Install {{Pkg|php-pgsql}} and edit the {{ic|php.ini}} file uncommenting the lines {{ic|1=extension=pdo_pgsql.so}} and {{ic|1=extension=pgsql.so}}, then restart {{ic|httpd}}.</div>Caseyclysmhttps://wiki.archlinux.org/index.php?title=Gaming&diff=420868Gaming2016-02-16T00:53:15Z<p>Caseyclysm: www4.gamesonlinux.com no longer appears to be in service.</p>
<hr />
<div>[[Category:Gaming]]<br />
[[da:List of games]]<br />
[[es:List of games]]<br />
[[it:List of games]]<br />
[[ja:ゲーム]]<br />
[[lt:Games]]<br />
[[ru:Gaming]]<br />
[[zh-cn:List of games]]<br />
{{Related articles start}}<br />
{{Related|List of games}}<br />
{{Related|Xorg}}<br />
{{Related|NVIDIA#Gaming using TwinView}}<br />
{{Related articles end}}<br />
<br />
This page only contains information about running games and related system configuration tips. For lists of popular games for GNU/Linux see [[List of games]].<br />
<br />
== Game environments ==<br />
<br />
Different environments exist to play games in Linux:<br />
<br />
* Native &ndash; Games written for Linux.<br />
* Browser &ndash; you need only browser and Internet connection to play these types of games.<br />
** HTML5 games use canvas and WebGL technologies and work in all modern browsers but can be slow on weak machines.<br />
** Plugin-based &ndash; you need to install plugin to play.<br />
*** [[Java]] Webstart &ndash; used to install cross-platform games very easily.<br />
*** [[Flash]] games are very common on the Web.<br />
*** Unity &ndash; specialized game plugin for browsers.<br />
* Specialized environments (software emulators) &ndash; &ndash; Required for running software designed for other architectures or systems, (Heed the copyright laws of your country!). Check the [[List of applications/Other#Emulators|list of emulators]] for more details.<br />
** [[Wine]] &ndash; allows running of some Windows games, as well as a large amount of Windows software. Performance in Wine varies, the additional CPU overhead will cause slowdown in some games while in some cases games may run faster. Consult [http://appdb.winehq.org/ Wine AppDB] for game-specific compatibility information.<br />
** [http://www.codeweavers.com/ Crossover Games] &ndash; members of the Codeweavers team are prime supporters of Wine. Using Crossover Games makes the installation & setting up of some games easier, more reliable & even possible, when compared to using other methods. Crossover is a paid commercial product, which also provides a [http://www.codeweavers.com/support/forums/ forum] where the developers are very much involved in the community. <br />
** [[DOSBox]] is a minimal virtual machine which runs a full DOS-compatible environment. It can be used to run classic DOS titles.<br />
** {{Pkg|scummvm}} is an all-in-one engine reimplementation of many classic point-and-click adventure games. A full list of compatible titles can be found on the [http://scummvm.org ScummVM website].<br />
** Similar to ScummVM, engine reimplementations exist for specific titles, such as Doom.<br />
* Virtual machines can be used to install compatible operating systems (such as Windows). [[VirtualBox]] has good 3D support.<br />
<br />
== Getting games ==<br />
<br />
=== Native ===<br />
<br />
A good number are available in the [[official repositories]] or in the [[AUR]]. [http://liflg.org/ Loki] provides installers for several games.<br />
<br />
=== Digital distribution ===<br />
<br />
* {{App|[[Wikipedia:Desura|Desura]]|Digital distribution platform featuring indie games. It can be considered good source of games (if you do not care about security and bugs too much).<br />
|http://www.desura.com/|{{AUR|desura}}}}<br />
<br />
* {{App|[[Steam]]|Famous digital distribution and communications platform developed by Valve. It has a large library with over 1000 Linux games. These include popular titles like Dota 2, Counter Strike: Global Offensive, Team Fortress 2, several AAA games, and lots of indie titles.<br />
|http://store.steampowered.com|{{Pkg|steam}}}}<br />
::*[http://developer.valvesoftware.com/wiki/Steam_under_Linux Steam under Linux.]<br />
::*[http://store.steampowered.com/browse/linux/ See linux-games catalog.]<br />
::*Not all Steam titles are native, some are packaged to run using Wine.<br />
<br />
* The [https://www.humblebundle.com/store Humble Store]<br />
<br />
* [https://itch.io/ itch.io]|{{AUR|itch}}<br />
<br />
* [http://www.gog.com/games/linux GOG.com]<br />
::*The {{AUR|lgogdownloader}} package can be used to download GOG titles from the command line.<br />
::*GOG.com only officially supports Ubuntu and Linux Mint. Bear this in mind if requesting support from them; you will not get a refund if you are having trouble running games on Arch.<br />
::*Many GOG.com titles come pre-packaged with DOSBox, ScummVM or Wine.<br />
<br />
=== Flash ===<br />
{{Note|The official Adobe Flash Player for Linux with NPAPI-based browsers is stuck at major version 11, whereas the current (as of August 25, 2015) major version is 18. An up-to-date Adobe Flash Player is, however, obtainable on Linux with PPAPI-based browsers. Please see [[wikipedia:Adobe Flash Player#Desktop platforms]] for more info. If you do not wish to install Chrome, however, there is an even more potent option to use the Windows version of Flash; see http://community.linuxmint.com/tutorial/view/2028 for details.}}<br />
<br />
Several huge Flash games portals exists, among them are:<br />
* https://armorgames.com/<br />
* https://www.kongregate.com/<br />
* https://www.newgrounds.com/<br />
<br />
=== Java ===<br />
<br />
* Lots of games smaller than 4kb (some are real masterpieces of game design) can be found at http://www.java4k.com.<br />
* https://www.pogo.com/ &ndash; biggest casual Java gaming portal<br />
* [http://www.javagametome.com/ The Java Game Tome] - huge database of primarily casual games<br />
<br />
=== Wine ===<br />
<br />
* Centralized source of information about running games (and other applications) in [[Wine]] is [http://appdb.winehq.org/ Wine AppDB].<br />
* See also [[:Category:Wine]].<br />
<br />
It is recommended (especially for beginners) to use {{Pkg|playonlinux}}, which pulls all necessary dependencies during installation, automatically downloads Windows tools at first start-up to configure and set-up native windows applications to launch properly. For more information, see [https://www.playonlinux.com/en/ Official Website].<br />
<br />
== Running games ==<br />
<br />
Certain games or game types may need special configuration to run or to run as expected.<br />
For the most part, games will work right out of the box in Arch Linux with possibly better performance than on other distributions due to compile time optimizations. However, some special setups may require a bit of configuration or scripting to make games run as smoothly as desired.<br />
<br />
=== Multi-screen setups ===<br />
<br />
Running a multi-screen setup may lead to problems with fullscreen games. In such a case, [[#Starting games in a separate X server|running a second X server]] is one possible solution. Another solution may be found in the [[NVIDIA#Gaming using TwinView|NVIDIA article]] (may also apply to non-NVIDIA users).<br />
<br />
=== Keyboard grabbing ===<br />
<br />
Many games grab the keyboard, noticeably preventing you from switching windows (also known as alt-tabbing).<br />
<br />
Some SDL games (e.g. Guacamelee) let you disable grabbing by pressing {{ic|Ctrl-g}}.<br />
<br />
You can also download {{AUR|sdl-nokeyboardgrab}}{{Broken package link|{{aur-mirror|sdl-nokeyboardgrab}}}} to gain the ability to use keyboard commands while in SDL games. If you wish to turn it up to 11, you can disable keyboard grabbing at X11 level using {{AUR|libx11-nokeyboardgrab}}, or with more fine-grained control with {{AUR|libx11-ldpreloadnograb}}{{Broken package link|{{aur-mirror|libx11-ldpreloadnograb}}}} using the {{ic|LD_PRELOAD}} environment variable to run applications with particular grab prevention. Wine/lib32 users should also look at the respective lib32 libraries.<br />
<br />
{{Note|SDL is known to sometimes not be able to grab the input system. In such a case, it may succeed in grabbing it after a few seconds of waiting.}}<br />
<br />
=== Starting games in a separate X server ===<br />
<br />
{{Merge|Running program in separate X display|same topic}}<br />
<br />
In some cases like those mentioned above, it may be necessary or desired to run a second X server. Running a second X server has multiple advantages such as better performance, the ability to "tab" out of your game by using {{ic|Ctrl+Alt+F7}}/{{ic|Ctrl+Alt+F8}}, no crashing your primary X session (which may have open work on) in case a game conflicts with the graphics driver. The new X server will be akin a remote access login for the ALSA, so your user need to be part of the {{ic|audio}} group to be able to hear any sound.<br />
<br />
To start a second X server (using [http://www.xonotic.org/ Xonotic] as an example) you can simply do: <br />
$ xinit /usr/bin/xonotic-glx -- :1 vt$XDG_VTNR<br />
This can further be spiced up by using a seperate X configuration file:<br />
$ xinit /usr/bin/xonotic-glx -- :1 -xf86config xorg-game.conf vt$XDG_VTNR<br />
A good reason to provide an alternative ''xorg.conf'' here may be that your primary configuration makes use of NVIDIA's Twinview which would render your 3D games like Xonotic in the middle of your multiscreen setup, spanned across all screens. This is undesirable, thus starting a second X with an alternative config where the second screen is disabled is advised.<br />
<br />
A game starting script making use of Openbox for your home directory or {{ic|/usr/local/bin}} may look like this:<br />
{{hc|~/game.sh|<nowiki><br />
if [ $# -ge 1 ]; then<br />
game="$(which $1)"<br />
openbox="$(which openbox)"<br />
tmpgame="/tmp/tmpgame.sh"<br />
DISPLAY=:1.0<br />
echo -e "${openbox} &\n${game}" > ${tmpgame}<br />
echo "starting ${game}"<br />
xinit ${tmpgame} -- :1 -xf86config xorg-game.conf || exit 1<br />
else<br />
echo "not a valid argument"<br />
fi<br />
</nowiki>}}<br />
<br />
So after a {{ic|chmod +x}} you would be able to use this script like:<br />
$ ~/game.sh xonotic-glx<br />
<br />
=== Adjusting mouse detections ===<br />
<br />
For games that require exceptional amount of mouse skill, adjusting the [[mouse polling rate]] can help improve accuracy.<br />
<br />
=== Mouse focus in GNOME ===<br />
<br />
{{Merge|GNOME}}<br />
<br />
The 'sloppy' and 'mouse' window-focusing modes in [[GNOME]] are known to cause issues with a variety of games, causing a 'click-through' effect. Users can remedy this problem by switching the focus mode to 'click' (with a tool such as {{Pkg|gnome-tweak-tool}}), playing in a different desktop environment, or spawing their game in a separate X-session.<br />
<br />
=== Binaural Audio with OpenAL ===<br />
<br />
For games using [[Wikipedia:OpenAL|OpenAL]], if you use headphones you may get much better positional audio using OpenAL's [[Wikipedia:Head-related transfer function|HRTF]] filters. To enable, run the following command:<br />
<br />
echo "hrtf = true" >> ~/.alsoftrc<br />
<br />
Alternatively, install {{AUR|openal-hrtf}} from the AUR, and edit the options in /etc/openal/alsoftrc.conf<br />
<br />
For Source games, the ingame setting `dsp_slow_cpu` must be set to `1` to enable HRTF, otherwise the game will enable its own processing instead. You will also either need to set up Steam to use native runtime, or link its copy of openal.so to your own local copy. For completeness, also use the following options:<br />
<br />
dsp_slow_cpu 1 # Disable in-game spatialiazation<br />
snd_spatialize_roundrobin 1 # Disable spatialization 1.0*100% of sounds<br />
dsp_enhance_stereo 0 # Disable DSP sound effects. You may want to leave this on, if you find it does not interfere with your perception of the sound effects.<br />
snd_pitchquality 1 # Use high quality sounds<br />
<br />
=== Tuning Pulseaudio ===<br />
<br />
If you are using [[PulseAudio]], you may wish to tweak some default settings to make sure it is running optimally.<br />
<br />
==== Enabling realtime priority and negative nice level ====<br />
<br />
Pulseaudio is built to be run with realtime priority, being an audio daemon. However, because of security risks of it locking up the system, it is scheduled as a regular thread by default. To adjust this, first make sure you are in the {{ic|audio}} group. Then, uncomment and edit the following lines in {{ic|/etc/pulse/daemon.conf}}:<br />
high-priority = yes<br />
nice-level = -11<br />
<br />
realtime-scheduling = yes<br />
realtime-priority = 5<br />
and restart pulseaudio.<br />
<br />
==== Using higher quality remixing for better sound ====<br />
<br />
Pulseaudio on Arch uses speex-float-0 by default to remix channels, which is considered a 'medium-low' quality remixing. If your system can handle the extra load, you may benefit from setting it to one of the following instead:<br />
resample-method = speex-float-10<br />
resample-method = src-sinc-best-quality<br />
<br />
==== Matching hardware buffers to Pulse's buffering ====<br />
<br />
Matching the buffers can reduce stuttering and increase performance marginally. See [http://forums.linuxmint.com/viewtopic.php?f=42&t=44862 here] for more details.<br />
<br />
=== Double check your CPU frequency scaling settings ===<br />
<br />
If your system is currently configured to properly insert its own cpu frequency scaling driver, the system sets the default governor to Ondemand. By default, this governor only adjusts the clock if the system is utilizing 95% of its CPU, and then only for a very short period of time. This saves power and reduces heat, but has a noticeable impact on performance. You can instead only have the system downclock when it is idle, by tuning the system governor. To do so, see [[Cpufrequtils#Improving on-demand performance]].<br />
<br />
== Improving framerates and responsiveness with scheduling policies ==<br />
Most every game can benefit if given the correct scheduling policies for the kernel to prioritize the task. However, without the help of a daemon, this rescheduling would have to be carried out manually or through the use of several daemons for each policy. These policies should ideally be set per-thread by the application itself, but not all developers implement these policies. There are several methods for getting them to work anyway:<br />
<br />
=== For Wine programs ===<br />
<br />
{{AUR|wine-rt}} is a patched version of Wine that implements scheduling policies on a per-thread basis, using the equivalent of what the Windows developers had intended the threads to be run at. The default patch is more oriented towards professional audio users, and tends to be too heavy-handed of an approach for gaming. You may instead wish to use [http://pastebin.com/D9GBzBBv this patch], which also includes nice levels and uses more than one policy decision. Be warned that it uses {{ic|SCHED_ISO}}, which is only properly implemented on [[Linux-ck]], and will simply renice {{ic|THREAD_PRIORITY_ABOVE_NORMAL}} threads if your system does not support it.<br />
<br />
=== For everything else ===<br />
<br />
For programs which do not implement scheduling policies on their own, one tool known as '''schedtool''', and its associated daemon {{AUR|schedtoold}} can handle many of these tasks automatically.<br />
To edit what programs relieve what policies, simply edit {{ic|/etc/schedtoold.conf}} and add the program followed by the ''schedtool'' arguments desired.<br />
<br />
==== Policies ====<br />
<br />
First and foremost, setting the scheduling policy to {{ic|SCHED_ISO}} will not only allow the process to use a maximum of 80 percent of the CPU, but will attempt to reduce latency and stuttering wherever possible. <br />
{{ic|SCHED_ISO}} requires [[Linux-ck]] to operate, as it has only been implemented in that kernel. [[Linux-ck]] itself provides a hefty latency reduction, and should ideally be installed <br />
Most if not all games will benefit from this:<br />
bit.trip.runner -I<br />
For users not using [[Linux-ck]], {{ic|SCHED_FIFO}} provides an alternative, that can even work better. You should test to see if your applications run more smoothly with {{ic|SCHED_FIFO}}, in which case by all means use it instead. Be warned though, as {{ic|SCHED_FIFO}} runs the risk of starving the system! Use this in cases where -I is used below:<br />
bit.trip.runner -F -p 15<br />
<br />
==== Nice levels ====<br />
<br />
Secondly, the nice level sets which tasks are processed first, in ascending order. A nice level of -4 is reccommended for most multimedia tasks, including games:<br />
bit.trip.runner -n -4<br />
<br />
==== Core affinity ====<br />
<br />
There is some confusion in development as to whether the driver should be multithreading, or the program. In any case where they both attempt it, it causes drops in framerate and crashes. Examples of this include a number of modern games, and any Wine program which is running without [[Wikipedia:OpenGL Shading Language|GLSL]] disabled. To select a single core and allow only the driver to handle this process, simply use the {{ic|-a 0x''#''}} flag, where ''#'' is the core number, e.g.: <br />
bit.trip.runner -a 0x1<br />
uses first core.<br />
Some CPUs are hyperthreaded and have only 2 or 4 cores but show up as 4 or 8, and are best accounted for:<br />
bit.trip.runner -a 0x5<br />
which use virtual cores 0101, or 1 and 3.<br />
<br />
==== General case ====<br />
<br />
For most games which require high framerates and low latency, usage of all of these flags seems to work best. Affinity should be checked per-program, however, as most native games can understand the correct usage.<br />
For a general case:<br />
bit.trip.runner -I -n -4<br />
Amnesia.bin64 -I -n -4<br />
hl2.exe -I -n -4 -a 0x1 #Wine with GLSL enabled<br />
etc.<br />
<br />
==== Optimus, and other helping programs ====<br />
<br />
As a general rule, any other process which the game requires to operate should be reniced to a level above that of the game itself. Strangely, Wine has a problem known as ''reverse scheduling'', it can often have benefits when the more important processes are set to a higher nice level. Wineserver also seems unconditionally to benefit from {{ic|SCHED_FIFO}}, since rarely consumes the whole CPU and needs higher prioritization when possible.<br />
optirun -I -n -5<br />
wineserver -F -p 20 -n 19<br />
steam.exe -I -n -5<br />
<br />
== Using alternate kernels ==<br />
<br />
{{Note|Many users report inconsistant framerate and other performance hits when using [[Linux-ck]], even if the overall framerate is sometimes higher. You may wish to try using {{Pkg|linux-zen}} if you just want BFQ.}}<br />
<br />
The stock Arch kernel provides a very good baseline for general usage. However, if your system has less than 16 cores and is intended for use primarily as a workstation, you can sacrifice a small amount of throughput on batch workloads and gain a significant boost to interactivity by using [[Linux-ck]]. If you prefer not to compile your own kernel, you can instead add [[Repo-ck]] and use one of their kernels. Using a pre-optimized kernel will most definitely offset any loss of throughput that may have occurred as a result, so be sure to select the appropriate kernel for your architecture. <br />
<br />
=== Using BFQ ===<br />
<br />
BFQ is an io-scheduler that comes as a feature of {{Pkg|linux-zen}} and [[Linux-ck]], and is optimized to be much more simplistic, but provides better interactivity and throughput for non-server workloads. To enable, simply add the kernel parameter ''elevator=bfq'' to your [[bootloader]]. It is important to note that although most guides recommend using either ''noop'' or ''deadline'' for SSDs for their raw throughput, they are actually detrimental to interactivity when more than one thread is attempting to access the device. It is best to use ''bfq'' unless you desperately need the throughput advantage.<br />
<br />
== See also ==<br />
<br />
* [http://www.linuxgames.com/ LinuxGames] - News on linux games<br />
* [http://osgameclones.com/ OSGameClones] - List of open source game clones<br />
* [http://freegamer.blogspot.com/ Free Gamer] - Open source games blog<br />
* [http://forum.freegamedev.net/ FreeGameDev] - Free/open source game development community<br />
* [https://fedoraproject.org/wiki/SIGs/Games#Gaming_News_sites SIG/Games] - OS/Linux gaming news sites and lists at Fedora's wiki<br />
* [http://live.linux-gamers.net live.linux-gamers] - Arch-based live gaming distro<br />
* [http://www.gamingonlinux.com/ Gaming on Linux] - Active Linux gaming news and editorial source and community</div>Caseyclysm