
<h3 class="page-heading">PostgreSQL Connection</h3>

<div class="gf-form-group">
	<div class="gf-form max-width-30">
		<span class="gf-form-label width-7">Host</span>
		<input type="text" class="gf-form-input" ng-model='ctrl.current.url' placeholder="localhost:5432" bs-typeahead="{{['localhost:5432', 'localhost:5433']}}" required></input>
	</div>

	<div class="gf-form max-width-30">
		<span class="gf-form-label width-7">Database</span>
		<input type="text" class="gf-form-input" ng-model='ctrl.current.database' placeholder="database name" required></input>
	</div>

	<div class="gf-form-inline">
		<div class="gf-form max-width-15">
			<span class="gf-form-label width-7">User</span>
			<input type="text" class="gf-form-input" ng-model='ctrl.current.user' placeholder="user"></input>
		</div>
		<div class="gf-form max-width-15" ng-if="!ctrl.current.secureJsonFields.password">
			<span class="gf-form-label width-7">Password</span>
			<input type="password" class="gf-form-input" ng-model='ctrl.current.secureJsonData.password' placeholder="password"></input>
    </div>
    <div class="gf-form max-width-19" ng-if="ctrl.current.secureJsonFields.password">
      <span class="gf-form-label width-7">Password</span>
      <input type="text" class="gf-form-input" disabled="disabled" value="configured">
      <a class="btn btn-secondary gf-form-btn" href="#" ng-click="ctrl.current.secureJsonFields.password = false">reset</a>
    </div>
	</div>
	<div class="gf-form">
		<label class="gf-form-label width-7">SSL Mode</label>
		<div class="gf-form-select-wrapper max-width-15 gf-form-select-wrapper--has-help-icon">
			<select class="gf-form-input" ng-model="ctrl.current.jsonData.sslmode" ng-options="mode for mode in ['disable', 'require', 'verify-ca', 'verify-full']" ng-init="ctrl.current.jsonData.sslmode"></select>
			<info-popover mode="right-absolute">
				This option determines whether or with what priority a secure SSL TCP/IP connection will be negotiated with the server.
			</info-popover>
		</div>
	</div>
</div>

<h3 class="page-heading">PostgreSQL details</h3>

<div class="gf-form-group">
	<div class="gf-form">
		<span class="gf-form-label width-9">
			Version
			<info-popover mode="right-normal" position="top center">
				This option controls what functions are available in the PostgreSQL query builder.
			</info-popover>
		</span>
		<span class="gf-form-select-wrapper">
			<select class="gf-form-input gf-size-auto" ng-model="ctrl.current.jsonData.postgresVersion" ng-options="f.value as f.name for f in ctrl.postgresVersions"></select>
		</span>
	</div>
	<div class="gf-form">
		<gf-form-switch class="gf-form" label="TimescaleDB" label-class="width-9" checked="ctrl.current.jsonData.timescaledb" switch-class="max-width-6"></gf-form-switch>
    <label class="gf-form-label query-keyword pointer" ng-click="ctrl.toggleTimescaleDBHelp()">
      Help&nbsp;
      <i class="fa fa-caret-down" ng-show="ctrl.showTimescaleDBHelp"></i>
      <i class="fa fa-caret-right" ng-hide="ctrl.showTimescaleDBHelp">&nbsp;</i>
    </label>
	</div>

	<div class="gf-form-inline">
		<div class="gf-form">
			<span class="gf-form-label width-9">Min time interval</span>
			<input type="text" class="gf-form-input width-6" ng-model="ctrl.current.jsonData.timeInterval" spellcheck='false' placeholder="1m"></input>
			<info-popover mode="right-absolute">
				A lower limit for the auto group by time interval. Recommended to be set to write frequency,
				for example <code>1m</code> if your data is written every minute.
			</info-popover>
		</div>
	</div>
<div class="grafana-info-box alert alert-info" ng-show="ctrl.showTimescaleDBHelp">
  <div class="alert-body">
    <p>
			<a href="https://github.com/timescale/timescaledb" class="pointer" target="_blank">TimescaleDB</a> is a time-series database built as a PostgreSQL extension. If enabled, Grafana will use <code>time_bucket</code> in the <code>$__timeGroup</code> macro and display TimescaleDB specific aggregate functions in the query builder.
    </p>
  </div>
</div>

</div>


<div class="gf-form-group">
	<div class="grafana-info-box">
		<h5>User Permission</h5>
		<p>
			The database user should only be granted SELECT permissions on the specified database &amp; tables you want to query.
			Grafana does not validate that queries are safe so queries can contain any SQL statement. For example, statements
			like <code>DELETE FROM user;</code> and <code>DROP TABLE user;</code> would be executed. To protect against this we
			<strong>Highly</strong> recommmend you create a specific PostgreSQL user with restricted permissions.
		</p>
	</div>
</div>

