Last active
August 29, 2015 14:19
-
-
Save d33tah/d01f3599e55e53d00f68 to your computer and use it in GitHub Desktop.
A minimalistic proof-of-concept PostgreSQL tuning tester tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from PyQt4 import QtCore | |
from PyQt4 import QtGui | |
from PyQt4 import uic | |
import sys | |
import psycopg2 | |
CONN_STRING = "host='localhost' dbname='postgres' user='d33tah'" | |
class MainWindow(QtGui.QMainWindow): | |
def __init__(self, parent=None): | |
self.conn = psycopg2.connect(CONN_STRING) | |
self.cur = self.conn.cursor() | |
QtGui.QMainWindow.__init__(self, parent) | |
self.ui = uic.loadUi('mainwindow.ui', self) | |
self.ui.propertySlider.sliderChanged = self.sliderMoved | |
QtCore.QObject.connect(self.ui.propertySlider, | |
QtCore.SIGNAL('valueChanged(int)'), | |
self.sliderMoved) | |
def sliderMoved(self, to): | |
scaled = to / 100.0 * 4 | |
self.ui.propertyValue.setText(str(scaled)) | |
self.cur.execute("SET cpu_tuple_cost='%s'" % scaled) | |
sql = "EXPLAIN " + str(self.ui.queryEdit.text()) | |
self.cur.execute(sql) | |
out = self.cur.fetchall() | |
explainResults = "" | |
for line in out: | |
explainResults += line[0] + "\n" | |
self.psqlOutput.document().setPlainText(explainResults) | |
def main(): | |
app = QtGui.QApplication(sys.argv) | |
window = MainWindow() | |
window.show() | |
app.exec_() | |
if __name__ == '__main__': | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<ui version="4.0"> | |
<class>MainWindow</class> | |
<widget class="QMainWindow" name="MainWindow"> | |
<property name="geometry"> | |
<rect> | |
<x>0</x> | |
<y>0</y> | |
<width>757</width> | |
<height>356</height> | |
</rect> | |
</property> | |
<property name="windowTitle"> | |
<string>MainWindow</string> | |
</property> | |
<widget class="QWidget" name="centralwidget"> | |
<layout class="QVBoxLayout" name="verticalLayout_2"> | |
<item> | |
<layout class="QHBoxLayout" name="horizontalLayout"> | |
<item> | |
<widget class="QLabel" name="label"> | |
<property name="text"> | |
<string>Query:</string> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<widget class="QLineEdit" name="queryEdit"> | |
<property name="text"> | |
<string>SELECT * FROM rdns</string> | |
</property> | |
</widget> | |
</item> | |
</layout> | |
</item> | |
<item> | |
<widget class="QPlainTextEdit" name="psqlOutput"> | |
<property name="readOnly"> | |
<bool>true</bool> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<layout class="QHBoxLayout" name="horizontalLayout_2"> | |
<item> | |
<widget class="QLabel" name="propertyLabel"> | |
<property name="text"> | |
<string>cpu_tuple_cost:</string> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<widget class="QSlider" name="propertySlider"> | |
<property name="orientation"> | |
<enum>Qt::Horizontal</enum> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<widget class="QLabel" name="propertyValue"> | |
<property name="text"> | |
<string>0</string> | |
</property> | |
</widget> | |
</item> | |
</layout> | |
</item> | |
</layout> | |
</widget> | |
<widget class="QMenuBar" name="menubar"> | |
<property name="geometry"> | |
<rect> | |
<x>0</x> | |
<y>0</y> | |
<width>757</width> | |
<height>20</height> | |
</rect> | |
</property> | |
</widget> | |
<widget class="QStatusBar" name="statusbar"/> | |
</widget> | |
<resources/> | |
<connections/> | |
</ui> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment